if not usage

python variable is determined None three kinds of writing:

  1、if x is None

  2、if not x

  3, if not x is None understood if not (x is None) 1, and the result is the opposite

 

python, None, false, "", 0, [], {}, (), the method using the judgment is not equal

  not None==not false==not ''==not 0==not[]==not{}==not()

>>> x = []
>>> y = None
>>> 
>>> x is None
False
>>> y is None
True
>>> 
>>> 
>>> not x
True
>>> not y
True
>>> 
>>> 
>>> not x is None
>>> True
>>> not y is None
False

Guess you like

Origin www.cnblogs.com/enhance/p/10947692.html