``if var'' and ``if var is not None''
Piet van Oostrum
piet-l at vanoostrum.org
Sun Sep 1 02:55:25 EDT 2019
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]
More information about the Python-list
mailing list