Python中的 not A 和 A is not None

Python中的 not A 和 A is not None,第1张

Python中的 not A 和 A is not None

not A 和 A is not None 两者并不是等价

  • not A 是判断A是否为0、False、空字符串、空列表、空字典、空元组以及None,满足任一条件即返回True
  • A is not None 是判断A是否为None,只要A不是None即返回True

如下例所示

>>A = None
>>B = []

>>A is not None
False
>>B is not None
True
>>not A
True
>>not B
True

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5659231.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-16
下一篇2022-12-16

发表评论

登录后才能评论

评论列表(0条)

    保存