gpt4 book ai didi

python - "is None"和 "== None"有什么区别

转载 作者:IT老高 更新时间:2023-10-28 12:09:50 31 4
gpt4 key购买 nike

我最近遇到了这种语法,我不知道有什么区别。

如果有人能告诉我其中的区别,我将不胜感激。

最佳答案

答案解释here .

引用:

A class is free to implement comparison any way it chooses, and it can choose to make comparison against None mean something (which actually makes sense; if someone told you to implement the None object from scratch, how else would you get it to compare True against itself?).

实际上,没有太大区别,因为自定义比较运算符很少见。但是您应该使用 is None 作为一般规则。

关于python - "is None"和 "== None"有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3257919/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com