第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

python 中的a is not None和 if a:區(qū)別

python 中的a is not None和 if a:區(qū)別

慕碼人8056858 2019-02-17 04:50:36
res=requests.get('https://www.zhipin.com/gongsi/_zzz_c101010100_iy100014_t801_s301/',headers=headers) turn=etree.HTML(res.text).xpath('//div[@class="page"]/a[contains(@ka,"page-next")]/@href') turn [] next_page is not None Traceback (most recent call last): File "<input>", line 1, in <module> NameError: name 'next_page' is not defined turn is not None True turn [] if turn: print('sss') turn is not None True turn is None False 為啥這個是空 寫is not None 是對的?這個is not None 什么時候用?
查看完整描述

5 回答

?
慕村9548890

TA貢獻(xiàn)1884條經(jīng)驗 獲得超4個贊

因為你寫的xpath沒有匹配到數(shù)據(jù),所以給你返回的是一個空的列表 空列表不是 None 'is not None' 類似 != None
== tests value where is tests to see if they are the same object

查看完整回答
反對 回復(fù) 2019-03-01
?
qq_笑_17

TA貢獻(xiàn)1818條經(jīng)驗 獲得超7個贊

因為 [] 是空列表,確實不是 None 啊。
if 的條件如果是 0, 空字符串 '', 空列表 [],布爾值 False,None,都會被判斷為 False,條件語句不執(zhí)行。

查看完整回答
反對 回復(fù) 2019-03-01
?
眼眸繁星

TA貢獻(xiàn)1873條經(jīng)驗 獲得超9個贊

xx is not None = xx != None
if xx = if xx != None and xx != '' and xx != False and xx != 0 and xx != [] and xx !={} and ...

查看完整回答
反對 回復(fù) 2019-03-01
?
LEATH

TA貢獻(xiàn)1936條經(jīng)驗 獲得超7個贊

題主需要了解下falsyFalse的區(qū)別, () [] None False 這些都是 Falsy的,但Falsy不只有這些。What is Truthy and Falsy in python? How is it different from True and False?

查看完整回答
反對 回復(fù) 2019-03-01
?
鴻蒙傳說

TA貢獻(xiàn)1865條經(jīng)驗 獲得超7個贊

None 是一個特殊的對象,而一個對象的布爾值是由__bool____len__ 特殊方法決定的。 None更多的時候作為sentinel對象使用,比如判斷循環(huán)是否執(zhí)行。

查看完整回答
反對 回復(fù) 2019-03-01
  • 5 回答
  • 0 關(guān)注
  • 4102 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號