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

 

原文出处:http://blog.csdn.net/Artprog/article/details/52197779

 

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(小于)


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

这里写图片描述
posted @ 2018-03-21 09:53  wangju003  阅读(728)  评论(0编辑  收藏  举报