Python 基础教程

Python 高级教程

Python 相关应用

Python 笔记

Python FAQ

original icon
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.knowledgedict.com/tutorial/python-keyword-not.html

Python not 关键字

Python 关键字 Python 关键字


Python中not关键字有如下3种用法:

  • not表示逻辑表达式“非”,not a 形式,取与a返回值相反的bool值。
  • 和in一起使用,形如a not in b,表示判断a不包含在b中。
  • 和is一起使用,形如a is not b,表示a和b不是指向同一个内存地址的变量引用。

具体示例如下:

a = False
if not a:
    print("逻辑非")

b = [1, 88]
c = 18
if c not in b:
    print("不包含")

d = None
e = ()
if e is not d:
    print("不是")

输出结果为:

逻辑非
不包含
不是