[EMAIL PROTECTED] a écrit :
i am confused.

x=5
y=5

x==y -> True
x is y -> True

shouldnt x is y return False since they shouldnt(dont?) point to the
same place in memory, they just store an equal value?

Python's "variable" do not "store values", they are name to object bindings. x = 5 is a shortand for globals()['x'] = int(5), which means "create an int instance with value 5 and bind it to the name 'x' in the global namespace'. wrt/ the identity test yielding true, it's the result of a CPython specific optimisation for small integer objects, that are cached and reused. Since Python integers are immutable, they can safely be shared. Now since it's an implementation specific thing, you should by no mean rely on it.

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to