what is the keyword "is" for?

Dan Bishop danb_83 at yahoo.com
Tue Aug 15 18:45:30 EDT 2006


Steve Holden wrote:
> daniel wrote:
> > Martin v. Löwis wrote:
> [...]
> >>For some objects, "change the object" is impossible. If you have
> >>
> >>a = b = 3
> >>
> >>then there is no way to change the object 3 to become 4 (say);
> >>integer objects are "immutable". So for these, to make a change,
> >>you really have to change the variable, not the value.
> >>
> >
> > sounds reasonable, I tried tuple which is also immutable, it behaves
> > the same as integers.
> >
> Well spotted. Tuples are indeed immutable, as are strings, unicode
> strings, integers and floats.

But tuples can contain mutable objects.

>>> a = (0, [1])
>>> a[1].append(2)
>>> a
(0, [1, 2])




More information about the Python-list mailing list