-2 python
我目前正在学习Python3,但我不了解逻辑运算符.这是链接:http: //pymbook.readthedocs.org/en/py3/operatorsexpressions.html#logical-operators 首先,它似乎应该返回"True"或"False"而不是其中一个输入数字.其次,我不明白为什么输出(输入数字之一)是这样的.请帮忙,谢谢.
操作员和返回最后,如果没有一个元素是元素False(或等效值,例如0).
例如,
>>> 1 and 4
4 # Given that 4 is the last element
>>> False and 4
False # Given that there is a False element
>>> 1 and 2 and 3
3 # 3 is the last element and there are no False elements
>>> 0 and 4
False # Given that 0 is interpreted as a False element
Run Code Online (Sandbox Code Playgroud)
运算符或返回第一个不是的元素False.如果没有这样的值,则返回False.
例如,
>>> 1 or 2
1 # Given that 1 is the first element that is not False
>>> 0 or 2
2 # Given that 2 is the first element not False/0
>>> 0 or False or None or 10
10 # 0 and None are also treated as False
>>> 0 or False
False # When all elements are False or equivalent
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
742 次 |
| 最近记录: |