面试题之常见优先级问题

1.括号>not>and>or

2.or与and的输出结果(两者相反,只要记住其中一个即可)

对于or而言,print(x or y),如果x为0,则输出后面的值y,否则则输出x(and与其相反,不做介绍)

print(1 or 2)   #输出结果为1
print(2 or 3)   #输出结果为2
print(0 or 3)   #输出结果为3
print(0 or 4)   #输出结果为4

3.逻辑运算符

and : 一假则假

or : 一真则真

not : 非

思考题:

print(3<1 and 5>6 or 3 and 4>5 or 8)
原文地址:https://www.cnblogs.com/yongyongyong/p/13824568.html