5 回答

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

TA貢獻(xiàn)1818條經(jīng)驗 獲得超7個贊
因為 []
是空列表,確實不是 None
啊。if
的條件如果是 0
, 空字符串 ''
, 空列表 []
,布爾值 False
,None
,都會被判斷為 False
,條件語句不執(zhí)行。

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 ...

TA貢獻(xiàn)1936條經(jīng)驗 獲得超7個贊
題主需要了解下falsy
和False
的區(qū)別, ()
[]
None
False
這些都是 Falsy
的,但Falsy
不只有這些。What is Truthy and Falsy in python? How is it different from True and False?

TA貢獻(xiàn)1865條經(jīng)驗 獲得超7個贊
None
是一個特殊的對象,而一個對象的布爾值是由__bool__
和__len__
特殊方法決定的。 None
更多的時候作為sentinel對象使用,比如判斷循環(huán)是否執(zhí)行。
添加回答
舉報