代码点读机 / Python / not

not Python · 关键字

把布尔值反过来,像反义词转换器:输入“是”,输出“否”;输入“否”,输出“是”

怎么用

not 条件

小例子

print(not True)   # False
print(not False)  # True

is_raining = False
if not is_raining:
    print("不下雨,可以出去玩")

运行结果

不下雨,可以出去玩

官方文档:https://docs.python.org/zh-cn/3/reference/expressions.html#boolean-operations

在代码里遇到不认识的词?打开代码点读机,点一下就懂 → ← Python全部词条