Equivalent code to the bool() built-in function

Raymond Hettinger python at rcn.com
Mon Apr 18 10:33:07 CEST 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


More information about the Python-list mailing list