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

Frank Millman frank at chagford.com
Sun Sep 1 02:33:46 EDT 2019


On 2019-09-01 8:12 AM, Hongyi Zhao wrote:
> Hi,
> 
> The following two forms are always equivalent:
> 
> ``if var'' and ``if var is not None''
> 
> Regards
> 

Not so. Here is an example -

 >>> var = []
 >>> bool(var)
False
 >>> bool(var is not None)
True
 >>>

Frank Millman




More information about the Python-list mailing list