[Tutor] Negative IF conditions

Kent Johnson kent37 at tds.net
Fri Feb 11 21:38:18 CET 2005


Mark Brown wrote:
> Hi,
> I'm a newbie and was wondering which of these IF conditions is better 
> structure:
> 
>    1. if not os.path.exists('filename'):

I prefer the above.

>    2. if os.path.exists('filename') == False:
> 
> They both work so if one preferred over the other?

Note that in Python in general, 'not x' and 'x == False' are not equivalent; 'not x' will be true 
for many more values than just False. For example
not 0
not 0.0
not []
not {}

are all True.

Kent

> Thanks
> Mark Brown
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list