On 16/6/2013 1:42 μμ, R. Michael Weylandt wrote:
I believe you are mistaken.
a here is not a pointer but variable,
which is a memory location that stores value 6.
b here is a pointer. It's value is the memory location of variable a which
stores value 6.
c here is just te same as a , a variable.
Actually, y'all both might be. This is a bit CPython specific and not
mandated by the language specification.
To Nikos: please don't extrapolate from the examples below. They are a
CPython (the most common implementation of the Python language)
specific detail.
## CODE SNIPPET##
a = 6; b = a; c = 6
id(a)
id(b)
id(c)
## END CODE##
These are all the same, indicating that they all point to the "same 6"
in memory. That's a CPython specific optimization (caching small
integers) which is not guaranteed by the language and changes between
pythons and between compiles.
For example,
## CODE SNIPPET##
a = 552315251254
b = a
c = 552315251254
a is b # True _on my machine_
I accept this if in the premise that, b boils down to actually point to
a's value, but it has to go through a first to find it, not directly.
a is c # False _on my machine_
Why false? These are 2 different memory locations storing the same number.
This should have been True.
Looks very weird.
a = memory location storing a value
b = memory location storing a's memory location
c = memory location storing a value, the same value as a
id(a)
id(b)
id(c)
## END CODE##
Note that to compare if two names point to the same "object, you can
use the "is" operator.
a is b
c is a
etc.
what id() does, never heard of that function before.
--
What is now proved was at first only imagined!
--
http://mail.python.org/mailman/listinfo/python-list