while true: !!!

Carsten Geckeler nospam at no.spam
Tue Dec 19 11:25:50 EST 2000


On Tue, 19 Dec 2000, Alex Martelli wrote:

> "Rainer Deyke" <root at rainerdeyke.com> wrote in message
> news:KTz%5.48644$x6.22165257 at news2.rdc2.tx.home.com...
> > "Steve Lamb" <grey at despair.rpglink.com> wrote in message
> > news:slrn93t7bv.le.grey at teleute.rpglink.com...
> > > On Mon, 18 Dec 2000 23:32:23 +0100 (MET), Carsten Geckeler
> > <nospam at no.spam>
> > > wrote:
> > > >`while true' would be more readable and clear than `while 1'.  By the
> > way,
> > > >explain a newbie that -1 is true. ;)
> > >
> > >     0 is true, all else is false.  And?  :P
> >
> > 0 is false, None is false, [] is false, () is false, {} is false, and x is
> > false where x is a class instance and x.__nonzero__() returns false.
> > Everything else is true.  I think.
> 
> Another couple of 'false's: a class instance which doesn't define
> __nonzero__ but does define __length__ when the latter returns 0;
> and, C-implemented user objects, similarly to class instances.
> 
> I don't _think_ there are any more...

Nice; It takes three tries of -- I assume -- experienced Python
programmers to find all cases of all statements evaluating as false. ;)

Cheers, Carsten
-- 
Carsten Geckeler:  carsten dot geckeler at gmx dot de
To get proper email-address replace `dot' and `at' by the corresponding symbols.





More information about the Python-list mailing list