日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

Python逻辑运算符 and ,or not 的理解

發(fā)布時(shí)間:2023/11/27 生活经验 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python逻辑运算符 and ,or not 的理解 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

要理解Python邏輯運(yùn)算符 and ,or not? 這三個(gè) ,你需要知道? 在 python里面,0、’’、[]、()、{}、None為 false,其它任何東西都為true

1 and(這個(gè)會(huì)java的話可以理解為邏輯與)

在 python里面,0、’’、[]、()、{}、None為 false,其它任何東西都為true
and 的理解 : 如果a或者b 中有0、’’、[]、()、{}、None 就返回 0、’’、[]、()、{}、None
也就是 a或者b 中有 false 就先返回false,如果a和b中都有false返回and前面的值
如果a或者b中都沒有false返回and后面的值

下面是驗(yàn)證代碼

# and 中1個(gè)都是false
a = 0
b = 10
print(a and b)  # 打印結(jié)果為 0
# and 中1個(gè)都是false
a = 10
b = ()
print(a and b)  # 打印結(jié)果為()
# and 中2個(gè)都是false
a = []
b = ()
print(a and b)  # 打印結(jié)果為[]
# and 中2個(gè)都是true
a = 10
b = 20
print(a and b)

2 or(這個(gè)會(huì)java的話可以理解為邏輯或)

在 python里面,0、’’、[]、()、{}、None為 false,其它任何東西都為true
or 的理解: 如果a或者b 中有非 0、’’、[]、()、{}、None 就不會(huì)返回 0、’’、[]、()、{}、None
也就是如果有一個(gè)ture的就返回true,如果a和b中都有false返回and后面面的值
如果a或者b中都沒有false返回and前面的值

驗(yàn)證代碼

# or 中1個(gè)都是false
a = 0
b = 10
print(a or b)  # 打印結(jié)果為 10
# or 中1個(gè)都是false
a = 10
b = ()
print(a or b)  # 打印結(jié)果為10
# or 中2個(gè)都是false
a = []
b = ()
print(a or b)  # 打印結(jié)果為()
# or 中2個(gè)都是true
a = 123
b = 456
print(a or b)  # 打印結(jié)果為123

3 not(這個(gè)會(huì)java的話可以理解為邏輯非)

在 python里面,0、’’、[]、()、{}、None為 false,其它任何東西都為true
如果 x 為 True,返回 False 。如果 x 為 False,它返回 True

# not為false
a = 0
print(not a)  # 返回True
# not為false
a = []
print(not a)  # 返回True
# not為false
a = {}
print(not a)  # 返回Tru
# not為true
a = 10
print(not a)  # 返回False

總結(jié)

以上是生活随笔為你收集整理的Python逻辑运算符 and ,or not 的理解的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。