Python学习之[逻辑运算]

逻辑运算是最基础的技能之一,主要考察我们的逻辑能力:

首先我们要知道 这三个词的意思 and or not 

and:并且

or:或

not:非真即假,非假即真

布尔值运算:

and:两端值都为真,其运算结果为真 如 True and True =True  只要有一个假就为假: True and False=False

or:两端只要有一个为真就是真 如: True or False=True 只要有一个真就为真

not True=False, not False=True

and or not 的运算顺序.

运算顺序 ()>not>and>or 

逻辑运算:

or : 如果两个数字 做逻辑运算 如 x or y. 如果x =0 则结果为y .如果x>0则为x

and :与or 相反 即可

练习:

1)、6 or 2 > 1      6
2), 3 or 2 > 1 3
3)、0 or 5 < 4 False
4)、5 < 4 or 3 3
5)、2 > 1 or 6 True
6)、3 and 2 > 1 True
7)、0 and 3 > 1 0
8)、2 > 1 and 3 3
9)、3 > 1 and 0 0
10)、3 > 1 and 2 or 2 < 3 and 3 and 4 or 3 > 2 2

猜你喜欢

转载自www.cnblogs.com/charles-lin/p/9588559.html
今日推荐