(例题)下面显示的代码输出是什么?
a = 1
b = 2
if a and b in [1, 2]:
print('1')
if a and b in [1, 3]:
print('2')
if a and b in [2, 3]:
print('3')
if a or b in [2, 3]:
print('4')
运行结果:
1
3
4
说明:
in运算符的优先级大于逻辑与、逻辑或
所以,a and b in [1, 2] 可以看成 a and (b in [1, 2])