Python中if not使用教程

python中判断变量是否为None三种写法:

1、if x is None

2、if not x

3、if not x is None 理解成 if not (x is None) 结果是和1相反的

python中None、false、""、0、[]、{}、()时,采用not 方法判断是相等的

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

很多人学习python,不知道从何学起。
很多人学习python,掌握了基本语法过后,不知道在哪里寻找案例上手。
很多已经做案例的人,却不知道如何去学习更加高深的知识。
那么针对这三类人,我给大家提供一个好的学习平台,免费领取视频教程,电子书籍,以及课程的源代码!QQ群:531509025

猜你喜欢

转载自blog.csdn.net/sinat_38682860/article/details/119960966