python基础--逻辑运算

#and or not
#and 且 :两边都为真才是真
#or 或:一个真就是真(一真为真)
#ont 非:相反
#优先级:1.not>and>or
#同一优先级由左向右以此计算!
#列子:print(2 > 1 and 1 < 4 or 2 < 3 and 9 > 6 or 2 < 4 and 3 < 2)
#T or T or F
#T or F
#结果为T
#'''x or y ---x为非零,则返回x'''
#ps int ----> bool 非零转换成bool 是True 0转换成bool 是False
print(bool(2))
print(bool(-10))
print(bool(100))
#bool----->int
print(int(True)) #1
print(int(False)) #0

#'''x or y ---x True,则返回x'''
print(1 or 2 ) #1
print(3 or 2) #3
print(0 or 2) #2
print(0 or 100) #100

#'''x and y ---x True,则返回y'''(相反)


posted @ 2019-12-04 17:02  故事的小黄花丶  阅读(250)  评论(0)    收藏  举报