>>> a,b = 1,2>>> a,b(1, 2)>>> cmp(a,b)Traceback (most recent call last):File "<interactive input>", line 1, in <module>NameError: name 'cmp' is not defined>>>
1 回答

慕婉清6462132
TA貢獻1804條經驗 獲得超2個贊
3開始沒這個函數了,官方文檔是這么寫的
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).)
大意就是cmp()函數已經“離開”了,如果你真的需要cmp()函數,你可以用表達式(a > b) - (a < b)代替cmp(a,b)
添加回答
舉報
0/150
提交
取消