Re: working with pointers



"Dave Brueck" <dave@xxxxxxxxxxxxxxxxxxx> wrote in message
news:mailman.299.1117566077.18027.python-list@xxxxxxxxxxxxx

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.


Michael wrote: > except numbers?? >

1) Please avoid top posting

2) '=' always makes a reference. It's just that

'b = 0' makes a *new* reference for b to 0, without changing the reference of a to 2.

b.pop() modifies the object referenced by b itself, which, since it is referenced by both a & b, means that the object referenced by a is also modified.

see also:

http://starship.python.net/crew/mwh/hacks/objectthink.html
.