python cmp import什么模块?

python cmp import什么模块


当年话下
浏览 742回答 3
3回答

智慧大石

cmp是Python2.x自带的比较函数,无需import模块。官方手册说明:cmp(x, y)Compare the two objects x and y and return an integer according to theoutcome. &nbsp;The return value is negative if x < y, zero if x == y andstrictly positive if x > y.如下所示:python3.x则取消了这个函数,以下是官方说明: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)

慕姐4208626

比如你一开始用的:import modulename如果修改的话,要这样:reload(modulename)
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python