温馨提示×

python逻辑运算符有哪些

养鱼的猫咪
2267
2021-03-18 15:00:56
栏目: 编程语言

python中的逻辑运算符:1.and运算符,将x和y做并列运算;2.or运算符,只要x和y两个条件有一个为True,那么整体结果就为True;3.not运算符,对x进行布尔取反,非真即假,非假即真;

python逻辑运算符有哪些

python中的逻辑运算符有以下几种

1.and运算符

and运算符作用:

and运算符的作用是将x和y做并列运算,如果x和y的结果都为True,则返回值为True;如果x和y有任意一个结果为False,则返回值为False。

and运算符语法:


x and y


and运算符使用方法:


True and True : True

True and False : False

False and True : False

False and False : False


2.or运算符

or运算符作用:

or运算符的作用是只要x和y两个条件有一个为True,那么整体结果就为True。

or运算符语法:


x or y


or运算符使用方法:


True or True : True

True or False : True

False or True : True

False or False : False


3.not运算符

not运算符作用:

not运算符的作用是对x进行布尔取反,非真即假,非假即真。

not运算符语法:


not x


not运算符使用方法:


not True : False

not False : True


month = 10

if not 1<=month<=12:

print('month不在1-12之间')



0