Test 0 and false since false is 0
Dan Sommers
dan at tombstonezero.net
Thu Jul 6 22:52:02 EDT 2017
On Fri, 07 Jul 2017 02:48:45 +0000, Stefan Ram wrote:
>>>> def isfalse( x ):
> ... return x == 0 and str( type( x )) == "<class 'bool'>"
> ...
>
Don't depend on string representations of objects, unless you know what
you're doing. Do this instead:
def isfalse(x):
return x == 0 and type(x) is bool
And why test against 0 in a function called isfalse?
def isfalse(x):
return x == False and type(x) is type(False)
Dan
More information about the Python-list
mailing list