我是靠谱客的博主 英俊母鸡,这篇文章主要介绍python 3里没有cmp这个函数了,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
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)

最后

以上就是英俊母鸡最近收集整理的关于python 3里没有cmp这个函数了的全部内容,更多相关python内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(40)

评论列表共有 0 条评论

立即
投稿
返回
顶部