溫馨提示×

python邏輯運算符有哪些

養魚的貓咪
2368
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
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女