python 中的a is not None和 if a:区别

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 NoneTraceback (most recent call last):
  File "<input>", line 1, in <module>
NameError: name 'next_page' is not defined
turn is not NoneTrueturn
[]if turn:
    print('sss')
    
turn is not NoneTrueturn is  NoneFalse为啥这个是空 写is not None 是对的?这个is not None 什么时候用?


慕的地10843
浏览 642回答 1
1回答

胡说叔叔

因为你写的xpath没有匹配到数据,所以给你返回的是一个空的列表 空列表不是 None 'is not None' 类似 != None== tests value where is tests to see if they are the same object
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python