Steven D'Aprano <[EMAIL PROTECTED]> wrote: > 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.
True, there are a lot of variables, but perhaps not as many as you think. For example, you can't get that output from IronPython or PyPy (or at least not the versions I have kicking around) as they won't print 'yes!' for the first test. You are correct though it is possible with both CPython and Jython. > 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? > I don't have a copy of 1.4 to check so I'll believe you, but you can certainly get the output I asked for with much more recent versions. For the answer I actually want each asterisk substitutes for exactly one character. -- http://mail.python.org/mailman/listinfo/python-list