Mutable objects inside tuples - good or bad?
Paul Kölle
paul at subsignal.org
Mon Apr 7 11:26:37 EDT 2014
Am 06.04.2014 09:25, schrieb Gary Herron:
> On 04/05/2014 11:53 PM, John Ladasky wrote:
>> I find this programming pattern to be useful... but can it cause
>> problems?
> No.
>
> What kind of problems are you considering? It won't break Python. It's
> perfectly legal code.
>
> The tuple c is still immutable, consisting of two specific objects, and
> (as always) without regard to the specifics or contents of those two
> objects.
It seems a tuple's immutability is debatable, or is this another
instance of the small-integer-reuse-implementation-detail-artifact?
Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a = ([1,2],[3,4])
>>> b = a
>>> a is b
True
>>> a == b
True
>>> c = (1,2,3)
>>> d = (1,2,3)
>>> c is d
False
>>> c == d
True
cheers
Paul
More information about the Python-list
mailing list