Variable Scope 2 -- Thanks for 1.

Duncan Booth me at
Sat Jan 10 13:14:35 CET 2004

JCM <joshway_without_spam at> wrote in
news:btn6ks$ada$1 at 

> Irmen de Jong <irmen at> wrote:
> ...
>> A very important concept with Python is that you don't have variable 
>> assignment, but name binding. An "assignment statement" binds a name
>> on an object, and the object can be of any type. A statement like
>> this: 
>> age = 29
>> doesn't assign the value 29 to the variable age. Rather, it labels
>> the integer object 29 with the name age.
> I think this statement is misleading--it seems to imply the integer
> object is altered somehow.  Personally I see no problem with saying
> the value 29 is assigned to the variable age, so long as you
> understand the semantics.

Be careful. The integer object is actually altered, at least in so far as 
its reference count (which is part of the object) is changed:

>>> import sys
>>> sys.getrefcount(29)
>>> age = 29
>>> sys.getrefcount(29)

Duncan Booth                      duncan.booth at
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?

More information about the Python-list mailing list