溫馨提示×

Python中邏輯取反的方法是什么

小億
136
2023-10-19 16:18:40
欄目: 編程語言

在Python中,邏輯取反可以使用`not`關(guān)鍵字來實(shí)現(xiàn)。通過在要取反的表達(dá)式前添加`not`關(guān)鍵字,即可得到邏輯取反的結(jié)果。
例如:
```python
x = True
y = not x
print(y)  # 輸出False
z = not (x and y)
print(z)  # 輸出True
```
在上述例子中,`not x`的結(jié)果是`False`,而`not (x and y)`的結(jié)果是`True`。

0