How to Teach Python "Variables"

Brian Blais bblais at bryant.edu
Tue Nov 27 13:52:59 EST 2007


On Nov 27, 2007, at Nov 27:1:21 PM, hdante wrote:

>  This shouldn't confuse a C programmer if he understands that
> assignment changes the pointer address, instead of copying the value:
>

Coming from C, I found the pointer analogy to work pretty well, but  
in my head I always felt that integers (or other numbers) were  
somehow different than lists, dicts and other classes.  I think I  
found it a little weird to think that --> 1 <-- is an object.  "You  
can't have all the integers as individual objects!", is what I  
thought...then I saw that is exactly how it is implemented.  So when  
you say:

a=1

it is *really* a pointer to a 1-object, and that

b=1  points to the same 1-object.

In [4]:id(a)
Out[4]:25180552

In [5]:b=1

In [6]:id(b)
Out[6]:25180552


						bb


-- 
Brian Blais
bblais at bryant.edu
http://web.bryant.edu/~bblais



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20071127/8c67d738/attachment.html>


More information about the Python-list mailing list