python中,not是保留字之一,也是python的逻辑运算符之一,执行的是布尔“非”的运算,比如not True的返回值为False,反过来,not False的返回值的则为True,类似于数学集合运算中的补集运算。除此之外,not还可以同in搭配使用,判断一个元素是否存在于某一个序列当中,也可以用于判断一个可迭代对象是否为空,具体可参考下方的实例。
>>> not True
False
>>> not False
True
>>> not 1
False
>>> not 0
True
>>> 5 not in range(6)
False
>>> 7 not in tuple(range(6))
True
>>> not ''
True
>>> not []
True
全栈编程 / python教程(可向下滚动):
Copyright © 2022-2023 笨鸟工具 x1y1z1.com All Rights Reserved.