while True or while 1

Chris Angelico rosuav at gmail.com
Sat Jan 21 09:59:01 EST 2012


On Sun, Jan 22, 2012 at 12:47 AM, Andrea Crotti
<andrea.crotti.0 at gmail.com> wrote:
> So I tried to do the following, and the result is surprising.  For what
> I can see it looks like the interpreter can optimize away the 1 boolean
> conversion while it doesn't with the True, the opposite of what I
> supposed.
>
> Anyone can explain me why is that, or maybe is my conclusion wrong?

In Python 3, they compile to the same code, because 'True' is a
keyword. In Python 2, you can reassign True to be 0.

ChrisA



More information about the Python-list mailing list