list vs tuple

Tim Peters tim.one at home.com
Sat Mar 31 15:35:26 EST 2001


[deadmeat]
> ...
> when the statement a = b copies the data across for one type it's
> expected to do it for others.

In Python,

    a = b

never copies data.  No exceptions.  It merely establishes a binding from the
name 'a' to whatever object 'b' is bound to at the time.  The type of the
object has no bearing on this.  Immediately after

    a = b

the Python expression

    a is b

returns true, provided only that b *was* bound to *some* object (else a
subclass of NameError is raised during the "a = b" line).

>>> b = 5
>>> a = b
>>> a is b
1
>>> b = [5]
>>> a = b
>>> a is b
1
>>>

can't-get-it-straight-until-you-give-up-on-what's-twisted-ly y'rs  - tim





More information about the Python-list mailing list