python3.x 之not and or详解

python3.x 之not and or详解


'''
知识点:
#优先级not>and>or
#and中含0,返回0; 均为非0时,返回后一个值
#or中, 至少有一个非0时,返回第一个非0
>>> 3 and 4
4
>>> 4 and 3
3
>>> 3 or 4
3
>>> 4 or 3
4
>>> 3 and 0
0
>>> 0 and 3
0
>>> 3 or 0
3
>>> 0 or 3
3
'''

a = True
b = False
c = 10
d = 'abc'

print(type(a>0))
#

print(a>0 and a)
#True

print(a and b)
#False

print(a and c)   #10
print(a and d)   #'abc'

print(b and a)   #False
print(b and b)   #False
print(b and c)  #False
print(b and d)  #False

print(c and a)  #True
print(c and b)  #False
print(c and c)  #10

print(c and d)  #abc

print(d and a)  #True
print(d and b)  #False
print(d and c)  #10
print(d and d)  #'abc'

print(5.0//2.0)  #2.0
print(5/2)       #2.5


print(4 and 3)   #3


#短路操作
print(0 or 4 or 6 or 9) #4    出现4后,后面的数被短路,不执行


'''
测试案例:
#判断:not 1 or 0 and 1 or 3 and 4 or 5 and 6 or 7 and 8 and 9
思路:
1.(not 1) or (0 and 1) or (3 and 4) or (5 and 6) or (7 and 8) and 9)
2. 0 or 0 or 4 or 6 or 8 and 9
3. 0 or 0 or 4 or 6 or 9
4. 0 or 4 or 6 or 9
5. 4 or 6 or 9
6. 4 or 9
7. 4
'''

你可能感兴趣的:(python)