作业04:逻辑运算

# 逻辑运算优先级:() >  not  >  and  >  or
print(2 > 1 and  4 <5 or 2 < 3 or 3 > 1 and 5 > 2)
print(2 > 3 and  4 <5 or 4 < 3 or 3 > 1 and 5 > 6)
print('--------')
# x or y , x为非零 ,则返回x  ,  x or y , x为True ,则返回x
print(1 or 3)
print(0 or 2)
print('--------')
# x and y , x为True ,则返回y
print(1 and 3)
print(0 and 2)
print('--------')
# int ----> bool 非零转换成bool为True, 0转换成bool 是False
print(bool(2))
print(bool(-2))
print(bool(0))
print('--------')
# bool ----> int  True False 第一位字母为大写
print(int(True))
print(int(False)

  

原文地址:https://www.cnblogs.com/elsa2007/p/10872568.html