Encapsulation unpythonic?
Marco Buttu
marco.buttu at gmail.com
Sat Aug 31 02:49:45 EDT 2013
On 08/31/2013 08:07 AM, Fabrice Pombet wrote:
> well, look at that:
>
> a=(1,2)
> a=2+3 ->a is an object and I have changed its type and value from outside.
No, `a` is not an object, so you did not change the type of any object.
`a` is just a name (a label), that initially refers to the tuple (1, 2):
>>> a = (1, 2)
>>> id(a)
140377464514968
ad after, to another object, of type int:
>>> a = 2 + 3
>>> id(a)
8752608
The bytecode:
>>> dis.dis('a = (1, 2); a = 2 + 3;')
1 0 LOAD_CONST 4 ((1, 2))
3 STORE_NAME 0 (a)
6 LOAD_CONST 5 (5)
9 STORE_NAME 0 (a)
12 LOAD_CONST 3 (None)
15 RETURN_VALUE
Regards, M.
--
Marco Buttu
More information about the Python-list
mailing list