working with pointers
Ivan Van Laningham
ivanlan at pauahtun.org
Tue May 31 15:09:01 EDT 2005
Hi All--
Dave Brueck wrote:
>
> Michael wrote:
> > sorry, I'm used to working in c++ :-p
> >
> > if i do
> > a=2
> > b=a
> > b=0
> > then a is still 2!?
> >
> > so when do = mean a reference to the same object
>
> Always.
>
> > and when does it mean make a copy of the object??
>
> Never.
>
To which I would add (without attempting to preserve Dave's admirable
brevity):
a=[3,5,6]
b=a
"b" is a reference to a; both b and a are names bound to "[3,5,6]".
a=[3,5,6]
b=a[:]
a and b are now bound to different instances of [3,5,6]
Metta,
Ivan
----------------------------------------------
Ivan Van Laningham
God N Locomotive Works
http://www.andi-holmes.com/
http://www.foretec.com/python/workshops/1998-11/proceedings.html
Army Signal Corps: Cu Chi, Class of '70
Author: Teach Yourself Python in 24 Hours
More information about the Python-list
mailing list