为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

慕的地10843 2019-02-05 19:53:04
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 什么时候用?
查看完整描述

1 回答

?
胡说叔叔

TA贡献1804条经验 获得超8个赞

因为你写的xpath没有匹配到数据,所以给你返回的是一个空的列表 空列表不是 None 'is not None' 类似 != None
== tests value where is tests to see if they are the same object

查看完整回答
反对 回复 2019-02-05
  • 1 回答
  • 0 关注
  • 641 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信