Home > other >  If x is not None with the if not x is None, if not the difference between x
If x is not None with the if not x is None, if not the difference between x

Time:10-06

1. If x is not None
2, if not x
3 if not x is None here x is equal to None, False, an empty string, 0, an empty list [], an empty dictionary {}, empty tuple () has no effect on your judgment,
That is:
Not None==not False.==not ' '==not 0==not []==not {}==the not ()

If x is not None; And if not x is None; Is the same, one is a different writing, is to determine whether x is equal to None, only x is not the time for None will perform a colon after the statement,

The code is as follows;
X=[]
Y=None
X is None
"False
Y is None
"True
X is notNone
"True
Y is not None
"False

You can see the not x and not all is True, y not [] and not None are equivalent, unable to distinguish between each other,
It is recommended to use the if x is not None; Google's writing,

  • Related