Pointers
Klaus-Gerd Meyer
Klaus-Gerd.Meyer at de.bosch.com
Tue Apr 18 17:13:21 CEST 2000
>Try playing around in the interpreter for a while, this is a key thing to
>understand about Python in my opinion. You can test objects to see if
>they're the same object with 'x is y', and test their values with 'x == y'.
A good idea. ;-)
Also nice: id(x), returns an objekt id (currently implemented as its
address).
Integers and strings with same value are identical, but tuples and list with
same value are not identical...
>>> x = 1
>>> y = 1
>>> id(x),id(y)
(7879224, 7879224)
>>> x is y #x and y: same value and identical
1
>>>
>>> x = "a"
>>> y = "a"
>>> id(x),id(y)
(8041104, 8041104)
>>> x is y #x and y: same value and identical
1
>>> x = ("a","b")
>>> y = ("a","b")
>>> id(x),id(y)
(8864080, 8919376)
>>> x is y #x and y: same value and not identical
0
>>> x = ["a"]
>>> y = ["a"]
>>> id(x),id(y)
(9378096, 9394512)
>>> x is y #x and y: same value and not identical
0
More information about the Python-list
mailing list