The cmp() function should be treated as gone, and the __cmp__() special method is no longer supported. Use __lt__() for sorting, __eq__() with __hash__(), and other rich comparisons as needed. (If you really need the cmp() functionality, you could use the expression (a > b) - (a < b) as the equivalent for cmp(a, b).)
^{} 函数仅在
Python 2.x
中。如official Python documentation中所述:Python 3.x
中的^{注意:元组(
myStupidTup
和mySmartTup
)不支持比较。如果运行它,您将得到一个TypeError
:TypeError: '>' not supported between instances of 'str' and 'int'
相关问题 更多 >
编程相关推荐