return boolean from functions

Michael Hudson mwh21 at cam.ac.uk
Thu Nov 4 07:17:14 EST 1999


a_olme at my-deja.com writes:

> Hello.
> 
> Is it possible to return booelan from functions other than return 1==1
> for true or return 1==2 for false?

Well, you could return 1 for true and 0 for false:

>>> print 1==1, type(1==1), 1==0, type(1==0)
1 <type 'int'> 0 <type 'int'>

Python does not have a distinct boolean type, if that's what you're
asking. Empty lists, empty strings, 0, 0L and 0.0 are false,
everything else is true (except for instances of classes that have
__nozero__ methods, which get to decide for themselves).

Chapter and verse:

http://www.python.org/doc/current/ref/lambda.html#Booleans

HTH,
Michael





More information about the Python-list mailing list