while True or while 1

Christian Heimes lists at cheimes.de
Sun Dec 12 10:30:38 EST 2010


Am 12.12.2010 15:14, schrieb Max Countryman:
> I'm sure this has been brought up many times, but a quick Googling didn't yield the decisive results I was hoping for, so I apologize if this has already been addressed in great detail somewhere else.
> 
> I am wondering what the rationale is behind preferring while True over while 1? For me, it seems that using True provides more clarity, but is that the only benefit? Is while 1 more prone to errors?

In Python 2.x, "while 1" is slightly faster than "while True". The
interpreter can't optimize "while True" because the name "True" can be
bind to another value. In Python 3.x it's no longer possible to rebind
the names True and False just like None in Python 2.x

Christian




More information about the Python-list mailing list