Finding the instance reference of an object

pjacobi.de at googlemail.com pjacobi.de at googlemail.com
Fri Oct 31 16:42:53 CET 2008


Instead of comparing integers:

> x = 1
> y = x  # does assignment make copies?
> y += 1
> assert x == 1
> => succeeds, which implies that Python makes a copy when assigning

with lists:

> x = [1]
> y = x  # does assignment make copies?
> y += [1]
> assert x == [1]
> => fails, which implies that Python uses references when assigning

Compare lists with tupels:

x = (1,)
y = x  # does assignment make copies?
y += (1,)
assert x == (1,)
=> succeeds, which implies *what*?

Regards,
Peter




More information about the Python-list mailing list