Pointers

Alan Daniels daniels at mindspring.com
Wed Mar 15 21:22:05 EST 2000


On Thu, 16 Mar 2000 09:44:45 +1100, the infinitely wise Richard Jones
(Richard.Jones at fulcrum.com.au) spoke forth to us, saying...

[snip...]
>In Python, the things you have come to know as variables are best
>thought of as "labels" for objects. In old-fashioned
>pointer-language-speak, they're about as equivalent to references or
>pointers as you're going to get.

For the benefit of the original poster, I'd like to also add that in
Python, whenever you invoke any of the comparison operators, you're
comparing the objects underneath, *not* the pointer values. Example:

>>> a = [1, 2, 3]
>>> b = [1, 2, 3]
>>> id(a)
135065392
>>> id(b)
134921328
>>> if a == b: print "True."
...
True.

See? Even though a and b are different objects (as shown by calling
"id" on them and getting different numbers), they evaluate to the
same, and that's why "True" prints out. Hope this helps.

-- 
=======================
Alan Daniels
daniels at mindspring.com
daniels at cc.gatech.edu



More information about the Python-list mailing list