Immutable and Mutable Types

Duncan Booth duncan.booth at invalid.invalid
Mon Mar 17 06:40:43 EDT 2008


"Diez B. Roggisch" <deets at nospam.web.de> wrote:

> Which is exactly what happens - the actual implementation chose to cache
> some values based on heuristics or common sense - but no guarantees are
> made in either way.

Here's a puzzle for those who think they know Python:

Given that I masked out part of the input, which version(s) of Python might 
give the following output, and what might I have replaced by asterisks?

>>> a = 1
>>> b = 5-4
>>> if a is b: print 'yes!'
...
yes!
>>> b = ****
>>> if a is b: print 'yes!'
...
>>> b
1
>>> type(b)
<type 'int'>



More information about the Python-list mailing list