[Tutor] Tutor Digest, Vol 117, Issue 32 ( Subject: Phython List values )

Satheesan Varier satheesan.varier at gmail.com
Mon Nov 18 12:08:32 CET 2013


Message: 7
Date: Mon, 18 Nov 2013 06:57:20 -0000
From: "Ayo Rotibi" <ayodejirotibi at aol.com>
To: <tutor at python.org>
Subject: [Tutor] Phython List values
Message-ID: <002901cee42b$6e346fe0$4a9d4fa0$@com>
Content-Type: text/plain; charset="us-ascii"

Hi,

I am a complete newbie to python.



I read that an assignment with an = on lists does not make a copy. Instead,
assignment makes the two variables point to the one list in memory. For
instance, if a = [1, 2, 3] and b=a, then b = [1, 2, 3].



However, I discovered that if I change the value in 'a',  'b' does not take
the new value.  I thought since it is pointing to the same storage as 'a',
'b' should take the new value.



Any explanation would be appreciated.



Dear Ayo ::  You should look at the order of execution:


>>> a=['a','b','c']
>>> b=a
>>> b.append('d')
>>> a
['a', 'b', 'c', 'd']

In your third step you reassigned b=['a','b','c']


Best wishes !
















_________________________________

Desire, Dedication, Determination

and a little bit of Talent



On Mon, Nov 18, 2013 at 5:35 AM, <tutor-request at python.org> wrote:

> Send Tutor mailing list submissions to
>         tutor at python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         https://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
>         tutor-request at python.org
>
> You can reach the person managing the list at
>         tutor-owner at python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
>
> Today's Topics:
>
>    1. Call Attribute error -  Was Re: Tutor Digest, Vol 117,    Issue
>       28 (Alan Gauld)
>    2. Re: Link required for difference between class and object
>       (Joel Goldstick)
>    3. Re: Link required for difference between class and object
>       (Mark Lawrence)
>    4. Re: basic function concept (Alex Kleider)
>    5. Re: basic function concept (Alex Kleider)
>    6. Re: Link required for difference between class and object
>       (Alan Gauld)
>    7. Phython List values (Ayo Rotibi)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Sun, 17 Nov 2013 15:23:06 +0000
> From: Alan Gauld <alan.gauld at btinternet.com>
> To: tutor at python.org
> Subject: [Tutor] Call Attribute error -  Was Re: Tutor Digest, Vol
>         117,    Issue 28
> Message-ID: <l6an0g$ap7$1 at ger.gmane.org>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> On 17/11/13 12:19, Satheesan Varier wrote:
> > class myclass():
> >          def test(self):
> >              print "print this line"
> >
> > if __name__ == '__main__':
> >            myclass.run()
> >
> > You can do the test run with an instance of that class, as follows:
> >
> >  >>> k=myclass()
> >
> >  >>> myclass.test(k)
> > print this line
>
> Or more conventionally
>
> k.test()
>
> Please don't post the entire digest when replying, remove any irrelevant
> material. Some people pay by the byte and don't
> want to pay for stuff they've already seen.
>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.flickr.com/photos/alangauldphotos
>
>
>
> ------------------------------
>
> Message: 2
> Date: Sun, 17 Nov 2013 10:29:48 -0500
> From: Joel Goldstick <joel.goldstick at gmail.com>
> To: Reuben <reuben.dlink at gmail.com>
> Cc: "tutor at python.org" <tutor at python.org>
> Subject: Re: [Tutor] Link required for difference between class and
>         object
> Message-ID:
>         <
> CAPM-O+xxzUiE_us8rj3TXN2vu-fZi__3ObsJCWgYbdsqetEuTQ at mail.gmail.com>
> Content-Type: text/plain; charset=UTF-8
>
> On Sun, Nov 17, 2013 at 7:24 AM, Reuben <reuben.dlink at gmail.com> wrote:
> > Hi All,
> >
> > It would be nice if someone could forward a link which explains classes
> and
> > object.
> > I am still struggling to understand classes and objects better.
> >
> > Regards,
> > Reuben
> >
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > To unsubscribe or change subscription options:
> > https://mail.python.org/mailman/listinfo/tutor
> >
>
> Have you looked here yet?  http://docs.python.org/2/tutorial/classes.html
>
> --
> Joel Goldstick
> http://joelgoldstick.com
>
>
> ------------------------------
>
> Message: 3
> Date: Sun, 17 Nov 2013 15:53:49 +0000
> From: Mark Lawrence <breamoreboy at yahoo.co.uk>
> To: tutor at python.org
> Subject: Re: [Tutor] Link required for difference between class and
>         object
> Message-ID: <l6aoq3$sm8$1 at ger.gmane.org>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> On 17/11/2013 12:24, Reuben wrote:
> > Hi All,
> >
> > It would be nice if someone could forward a link which explains classes
> > and object.
> > I am still struggling to understand classes and objects better.
> >
> > Regards,
> > Reuben
> >
>
> An extremely simplistic answer to get you going, a class is the template
> that you have in your source code, an object is an instance of your
> class that you create in your source code.
>
> class Myclass(): #the class, the template
>      pass
>
> myobject = Myclass() # the instance, the object
>
> --
> Python is the second best programming language in the world.
> But the best has yet to be invented.  Christian Tismer
>
> Mark Lawrence
>
>
>
> ------------------------------
>
> Message: 4
> Date: Sun, 17 Nov 2013 08:54:01 -0800
> From: Alex Kleider <akleider at sonic.net>
> To: tutor at python.org
> Subject: Re: [Tutor] basic function concept
> Message-ID: <4d80fa567c0764c1441b8ea6dd9f2462 at sonic.net>
> Content-Type: text/plain; charset=UTF-8; format=flowed
>
> On 2013-11-17 00:47, Alan Gauld wrote:
> > On 17/11/13 05:16, Alex Kleider wrote:
> >> On 2013-11-16 13:20, Byron Ruffin wrote:
> >>> def main(x, y, z):
> >>>     print (x, y, z)
> >>>
> >>> def funct():
> >>>     x = 1
> >>>     y = 2
> >>>     z = 3
> >>>     return x, y, z
> >>>
> >>> main()
> >>>
> >>> Can someone tell me why main is not being given any arguments?
> >>
> >> Because you didn't give it any.
> >> Try
> >> main(funct())
> >
> > make that
> >
> > main(*funct())
> >
> > funct returns a tuple so you need to unpack it in the main()
> > argument list using the * notation.
>
>
> Much more elegant than my 'corrected' version.
> Thanks for the suggestion.
>
>
> ------------------------------
>
> Message: 5
> Date: Sun, 17 Nov 2013 08:51:48 -0800
> From: Alex Kleider <akleider at sonic.net>
> To: John Aten <welcome.to.eye.o.rama at gmail.com>
> Cc: tutor at python.org
> Subject: Re: [Tutor] basic function concept
> Message-ID: <f371a12ec16273f09fa5915f6362cd16 at sonic.net>
> Content-Type: text/plain; charset="utf-8"; Format="flowed"
>
> On 2013-11-16 22:31, John Aten wrote:
> > Too bad that doesn't work.
>
> No, it doesn't.  Can you see why?
> Attached is a version that does work but you'd be better served looking
> at the two versions you already have and studying the error messages you
> get when you run them.
>
>
> >
> > On Nov 16, 2013, at 11:16 PM, Alex Kleider wrote:
> >
> >> On 2013-11-16 13:20, Byron Ruffin wrote:
> >>> def main(x, y, z):
> >>>     print (x, y, z)
> >>> def funct():
> >>>     x = 1
> >>>     y = 2
> >>>     z = 3
> >>>     return x, y, z
> >>> main()
> >>> Can someone tell me why main is not being given any arguments?
> >>
> >> Because you didn't give it any.
> >> Try
> >> main(funct())
> >> instead.
> >>
> >>
> >>> _______________________________________________
> >>> Tutor maillist  -  Tutor at python.org
> >>> To unsubscribe or change subscription options:
> >>> https://mail.python.org/mailman/listinfo/tutor
> >> _______________________________________________
> >> Tutor maillist  -  Tutor at python.org
> >> To unsubscribe or change subscription options:
> >> https://mail.python.org/mailman/listinfo/tutor
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: func0args
> Type: text/x-python
> Size: 441 bytes
> Desc: not available
> URL: <
> http://mail.python.org/pipermail/tutor/attachments/20131117/5a05cb29/attachment-0001.py
> >
>
> ------------------------------
>
> Message: 6
> Date: Sun, 17 Nov 2013 17:20:56 +0000
> From: Alan Gauld <alan.gauld at btinternet.com>
> To: tutor at python.org
> Subject: Re: [Tutor] Link required for difference between class and
>         object
> Message-ID: <l6atte$gi5$1 at ger.gmane.org>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> On 17/11/13 12:24, Reuben wrote:
> > Hi All,
> >
> > It would be nice if someone could forward a link which explains classes
> > and object.
> > I am still struggling to understand classes and objects better.
>
> You can try the OOP topic in my tutorial if you like...
> In a nutshell:
>
> A class is a type, like string or integer are types.
> An instance is a 'value' of that type, like 'foo' or 42.
> Classes define methods (or operations) that you can apply
> to the instances, like 'foo'.upper().
>
> You can create your own data types by writing classes.
> But nearly all you should ever do with a class itself
> is create instances of it (at least as a beginner).
> Most of the work is done by the instances, by calling
> their methods.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.flickr.com/photos/alangauldphotos
>
>
>
> ------------------------------
>
> Message: 7
> Date: Mon, 18 Nov 2013 06:57:20 -0000
> From: "Ayo Rotibi" <ayodejirotibi at aol.com>
> To: <tutor at python.org>
> Subject: [Tutor] Phython List values
> Message-ID: <002901cee42b$6e346fe0$4a9d4fa0$@com>
> Content-Type: text/plain; charset="us-ascii"
>
> Hi,
>
> I am a complete newbie to python.
>
>
>
> I read that an assignment with an = on lists does not make a copy. Instead,
> assignment makes the two variables point to the one list in memory. For
> instance, if a = [1, 2, 3] and b=a, then b = [1, 2, 3].
>
>
>
> However, I discovered that if I change the value in 'a',  'b' does not take
> the new value.  I thought since it is pointing to the same storage as 'a',
> 'b' should take the new value.
>
>
>
> Any explanation would be appreciated.
>
>
>
> Ayo
>
>
>
> _________________________________
>
> Desire, Dedication, Determination
>
> and a little bit of Talent
>
>
>
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL: <
> http://mail.python.org/pipermail/tutor/attachments/20131118/59d3b0c1/attachment.html
> >
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> https://mail.python.org/mailman/listinfo/tutor
>
>
> ------------------------------
>
> End of Tutor Digest, Vol 117, Issue 32
> **************************************
>



-- 
Warm regards.

Satheesan Varier
860 (970) 2732
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20131118/a70e649e/attachment-0001.html>


More information about the Tutor mailing list