Tell me the truth
Mikael Olofsson
mikael at isy.liu.se
Thu Mar 8 11:27:19 EST 2007
francois.petitjean at bureauveritas.com wrote:
> If I take into account the fact that 'True' and 'False' are singletons
> (guaranteed ?) :
> (not not x) is bool(x) # should be always True.
> [snip code and results of code]
>
Consider the following:
>>> def ok1(x):
return (not not x) is bool(x)
>>> def ok2(x):
return (not not x) is bool(x) is True
>>> def ok3(x):
return ok1(x) is True
>>> def ok4(x):
return ((not not x) is bool(x)) is True
>>> def ok5(x):
return ((not not x) is bool(x)) and (bool(x) is True)
>>> for x in [False, True]:
print x,ok1(x), ok2(x), ok3(x), ok4(x), ok5(x)
False True False True True False
True True True True True True
Note that ok2(x) and ok5(x) exhibit the same behaviour.
HTH
/MiO
More information about the Python-list
mailing list