一切都比没有更大吗?
除了None
之外,是否还有Python内置数据类型:其中
>>> not foo > None
True
foo
是该类型的值? Python 3 怎么样?
Is there a Python built-in datatype, besides None
, for which:
>>> not foo > None
True
where foo
is a value of that type? How about Python 3?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
None
始终小于 Python 2 中的任何数据类型(请参阅object.c
)。在 Python 3 中,这一点发生了改变;现在,在没有合理自然排序的情况下对事物进行比较会导致
TypeError
。来自3.0“新增内容”更新:这让一些人感到不安,因为通常可以很方便地执行一些操作,例如对其中包含一些
None
值的列表进行排序,并使None
值在开头聚集在一起,或者结尾。 有一个线程不久前,邮件列表上就提到了这一点,但最终的要点是,Python 3 试图避免对排序做出任意决定(这在 Python 2 中经常发生)。None
is always less than any datatype in Python 2 (seeobject.c
).In Python 3, this was changed; now doing comparisons on things without a sensible natural ordering results in a
TypeError
. From the 3.0 "what's new" updates:This upset some people since it was often handy to do things like sort a list that had some
None
values in it, and have theNone
values appear clustered together at the beginning or end. There was a thread on the mailing list about this a while back, but the ultimate point is that Python 3 tries to avoid making arbitrary decisions about ordering (which is what happened a lot in Python 2).来自 Python 2.7.5 源 (
object.c
):编辑:添加版本号。
From the Python 2.7.5 source (
object.c
):EDIT: Added version number.