Equivalent code to the bool() built-in function

Raymond Hettinger python at rcn.com
Mon Apr 18 04:33:07 EDT 2011


On Apr 16, 1:24 pm, candide <cand... at free.invalid> wrote:
> Consider the following code :
>> # --------------------------------------
> def bool_equivalent(x):
>      return True if x else False

It's faster to write:
def bool_equivalent(x):
 return not not x
Raymond


More information about the Python-list mailing list

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