Equivalent code to the bool() built-in function

candide candide at free.invalid
Sat Apr 16 16:24:37 EDT 2011


Consider the following code :
# --------------------------------------
def bool_equivalent(x):
 return True if x else False
# testing ...
def foo(x):
 return 10*x
class C:
 pass
for x in [42, ("my","baby"), "baobab", max, foo, C] + [None, 0, "", [], 
{},()]:
 print bool(x)==bool_equivalent(x)
# --------------------------------------
Is the bool_equivalent() function really equivalent to the bool() 
built-in function ?


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /