return boolean from functions

Mark Hammond MHammond at
Thu Nov 4 18:14:52 EST 1999

Michael Hudson wrote in message ...
>a_olme at writes:
>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).

Actually, Python sort-a does have a concept of booleans.  There are PyTrue
and PyFalse objects, but they are not exposed to the runtime in any
meaningful way.  Eg:

>>> 1==1
>>> 1 is 1
>>> (1==1) is 1

Not that this really means anything practical, but there you have it...


More information about the Python-list mailing list