gpt4 book ai didi

python - 在 Python 中,None 的计算结果小于零?

转载 作者:IT老高 更新时间:2023-10-28 22:09:27 26 4
gpt4 key购买 nike

在 Python 中,None 的计算结果小于零?

ActivePython 2.7.2.5 (ActiveState Software Inc.) based on
Python 2.7.2 (default, Jun 24 2011, 12:21:10) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> None < 0
True
>>> None == 0
False
>>> None > 0
False
>>>

这是预期的吗?

我会猜到 None 要么等于零(通过类型强制),要么所有这些语句都会返回 False

最佳答案

the manual :

Objects of different types, except different numeric types and different string types, never compare equal; such objects are ordered consistently but arbitrarily (so that sorting a heterogeneous array yields a consistent result).

CPython implementation detail: Objects of different types except numbers are ordered by their type names; objects of the same types that don’t support proper comparison are ordered by their address.

关于python - 在 Python 中,None 的计算结果小于零?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7383782/

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