while True or while 1

Erik Max Francis max at alcyone.com
Sat Jan 21 16:14:24 EST 2012

Andrea Crotti wrote:
> I see sometimes in other people code "while 1" instead of "while True".
> I think using True is more pythonic, but I wanted to check if there is
> any difference in practice.

No (with the exception of `True` and `False` being rebinable in Python 
2).  The idiomatic `while 1` notation comes from back in the pre-Boolean 
days.  In any reasonably modern implementation, `while True` is more 
self-documenting.  I would imagine the primary reason people still do 
it, any after-the-fact rationalizations aside, is simply habit.

Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
  San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Jabber erikmaxfrancis
   Ambition can creep as well as soar.
    -- Edmund Burke

More information about the Python-list mailing list