慕侠0006521
2021-11-10 08:55
cmp(12,52)
Traceback (most recent call last):
File "<pyshell#37>", line 1, in <module>
cmp(12,52)
NameError: name 'cmp' is not defined
Python 3的版本中已经没有 cmp 函数,如果你需要实现比较功能,需要引入 operator 模块,适合任何对象,包含的方法有:
operator.lt(a, b)operator.le(a, b)operator.eq(a, b)operator.ne(a, b)operator.ge(a, b)operator.gt(a, b)
Python3 入门教程(新版)
163604 学习 · 1130 问题
相似问题