'if name is not None:' v. 'if name:'

Larry Bates larry.bates at websafe.com`
Tue Jul 15 20:46:14 CEST 2008


Victor Noagbodji wrote:
> Hello,
> 
> what's the difference between these two statement? And which one should one use?
> 

if name ...

Will be false if:

name is an integer == 0
name is a float == 0
name is an empty string
name is an empty list
name is an empty dictionary

There are others, but you get the idea.

If name is not None:

Is false only if name is not None but will
be true for all the others.

-Larry



More information about the Python-list mailing list