git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

``if var'' and ``if var is not None''


Hongyi Zhao <hongyi.zhao at gmail.com> writes:

> Hi,
>
> The following two forms are always equivalent:
>
> ``if var'' and ``if var is not None'' 
>
> Regards


In [1]: var = 0

In [2]: if var:
   ...:     print('True')
   ...: else:
   ...:     print('False')
False

In [3]: if var is not None:
   ...:     print('True')
   ...: else:
   ...:     print('False')
True

-- 
Piet van Oostrum <piet-l at vanoostrum.org>
WWW: http://piet.vanoostrum.org/
PGP key: [8DAE142BE17999C4]