我正在寻找一组好的哨兵值,例如实验:
[] > "sdfasfg" > ()
这似乎已记录在案:
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. reference
以同样的方式,
object() < str()
“最大”内置类型似乎是 unicode
,我可以使用什么作为与 unicode 类型进行比较的“正确”标记值?这是一个比任何 unicode 字符串都大的值?
Python 中内置类型实例的比较顺序真的定义得很好吗?
最佳答案
任意对象的比较称为“丰富的比较”。有一些文档here ,和 here 。
如果您使用的是 Python 3,请检查此 out 。来自此来源的相关引用:
Having both the rich comparison methods and the
__cmp__()
method violates the principle that there should be only one obvious way to do it, so in Python 3 the support for__cmp__()
has been removed. For Python 3 you therefore must implement all of the rich comparison operators if you want your objects to be comparable.
关于python - python内置类型的比较排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17408362/