[Tutor] immutable objects
Premnath Sah
prem.sah at gmail.com
Tue Oct 31 13:58:06 CET 2006
Hi,
from http://docs.python.org/ref/objects.htm
"""Types affect almost all aspects of object behavior. Even the importance
of object identity is affected in some sense: for immutable types,
operations that compute new values may actually return a reference to any
existing object with the same type and value, while for mutable objects this
is not allowed. E.g., after "a = 1; b = 1", a and b may or may not refer to
the same object with the value one, depending on the implementation, but
after "c = []; d = []", c and d are guaranteed to refer to two different,
unique, newly created empty lists. (Note that "c = d = []" assigns the same
object to both c and d.)"""
I would like to know how i can guarantee that a new immutable object is
infact a new object.
Example:
>>> a = 1
>>> b = 1
>>> a is b
True
is what i get. i want a and b to be two different object.
Thanks in advance
Premnath Sah T. H.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20061031/a158c552/attachment.htm
More information about the Tutor
mailing list