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

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

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

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

    原文作者:Artprog
    原文地址: https://blog.csdn.net/artprog/article/details/52197779
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞