Immutable and Mutable Types

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Mon Mar 17 09:37:39 EDT 2008


On Mon, 17 Mar 2008 10:40:43 +0000, Duncan Booth wrote:

> 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?

There's too many variables -- at least five Python implementations that I 
know of (CPython, Jython, PyPy, IronPython, and the Lisp-based 
implementation that I can never remember the name of), and given that 
this is an implementation-dependent feature it could have changed at any 
time, in any version number (say, between minor releases). And there's 
literally an infinite number of ways to get b equal to an int with the 
value 1.

So I think unless somebody happens to have stumbled across this 
behaviour, it's not predictable.

But having said that, I'm going to take a stab in the dark:

The line "b = ****" should be "b = int('1')"

and the version is CPython 1.4.

Am I close?


-- 
Steven



More information about the Python-list mailing list