Python3中替代Python2中cmp()函数的新函数(gt,ge,eq,le,lt)

来源:互联网 发布:淘宝纳米碳溶胶 编辑:程序博客网 时间:2024/05/22 05:14

Python3中已经不能使用cmp()函数了,被如下五个函数替代:

import operator       #首先要导入运算符模块operator.gt(1,2)      #意思是greater than(大于)operator.ge(1,2)      #意思是greater and equal(大于等于)operator.eq(1,2)      #意思是equal(等于)operator.le(1,2)      #意思是less and equal(小于等于)operator.lt(1,2)      #意思是less than(小于)

即使用上面五个英文缩写作为函数名:

这里写图片描述

2 0
原创粉丝点击