1.在没有()的情况下,not的优先级高于and,and的优先级高于or,即优先级关系为()>not>and>or,同一优先级从左往右计算。
例题,判断下列逻辑语句的结果:
3 > 4 or 4 < 3 and 1 == 1
1 < 2 and 3 < 4 or 1 > 2
2 > 1 and 3 < 4 or 4 > 5 and 2 < 1
1 > 2 and 3 < 4 or 4 > 5 and 2 > 1 or 9 < 8
1 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6
not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6
- x or y, 当x为True时,值就是x;x为False, 值就是False
x and y, x 为True,值是y; x 为False, 值是X
例题:求出下列逻辑语句的值
8 or 4
0 and 3
0 or 4 and 3 or 7 or 9 and 6
- in, not in
判断子元素是否在原字符串(字典,列表,集合)中:
例如:
print("a" in "abc")
print("a" not in "abc")