python 中小于负无穷大的数?
A number smaller than negative infinity in python?
这在 python2 中是可能的:
None < float('-inf')
此外,它总是 returns
True
但是,在 python3 上,这会抛出
TypeError: unorderable types: NoneType() < int()
为什么 None
与 integers/floats 和 python2 相当?在 python2 中订购 None
有什么好处或应用吗?
首先Python 2允许比较所有类型的混合类型。这个疣最终是fixed in Python 3。
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.
对于 None
Python 中的 quick decision was made by Guido and Tim Peters and it resulted in this commit 2.1(强调我的):
Part of fixing that was removing some cases of "compare objects of
different types by comparing the type name strings". Guido & I were
both in the office at the time, and one said to the other: "what about
None
? Comparing that to other types via comparing the string 'None'
doesn't make much sense." "Ya, OK ... how about changing None
to - by
default - comparing 'less than' objects of other types?" "Don't see
why not - sure." "OK, done!
No more than 2 minutes of thought went into it. There was no intent
to cater to any real use case here - the only intent was to pick some
arbitrary-but-consistent rule that didn't suck quite as badly as
pretending None was the string "None" ;-)
这在 python2 中是可能的:
None < float('-inf')
此外,它总是 returns
True
但是,在 python3 上,这会抛出
TypeError: unorderable types: NoneType() < int()
为什么 None
与 integers/floats 和 python2 相当?在 python2 中订购 None
有什么好处或应用吗?
首先Python 2允许比较所有类型的混合类型。这个疣最终是fixed in Python 3。
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.
对于 None
Python 中的 quick decision was made by Guido and Tim Peters and it resulted in this commit 2.1(强调我的):
Part of fixing that was removing some cases of "compare objects of different types by comparing the type name strings". Guido & I were both in the office at the time, and one said to the other: "what about
None
? Comparing that to other types via comparing the string'None'
doesn't make much sense." "Ya, OK ... how about changingNone
to - by default - comparing 'less than' objects of other types?" "Don't see why not - sure." "OK, done!No more than 2 minutes of thought went into it. There was no intent to cater to any real use case here - the only intent was to pick some arbitrary-but-consistent rule that didn't suck quite as badly as pretending None was the string "None" ;-)