[Tutor] while with function

alan.gauld@bt.com alan.gauld@bt.com
Mon Nov 18 06:10:16 2002


> > while 1:
> >     if y: break
> > ###
> 
> As I read this it means: if y is any number, exit the loop?

It means if y is any number other than zero.
Python considers zero false and all other numbers true.
Similarly it considers empty strings false and non empty 
strings true.

The purist in me thinks this is a nasty frig picked up from C 
that should be avoided.

The pragmatist in me says it saves some typing and isn't 
really that obscure...

:-)

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld