'if name is not None:' v. 'if name:'
russblau at hotmail.com
Tue Jul 15 21:50:09 CEST 2008
"Victor Noagbodji" <noagbodjivictor at gmail.com> wrote in message
news:fdd6be670807151244v6d63e5baj7e316a4ce861ac80 at mail.gmail.com...
> Well that's exactly why I'm asking. Since None returns False in if
> statements. Why do people use if name is not None: instead of simply
> writing if not name?
Because '' is a string value that is treated as false. If name=='', then
"if name:" will be false, but "if name is not None:" will be true. Which
one to use depends entirely on how you want to treat empty strings. For all
other (string) values of name, the two statements will give the same
More information about the Python-list