python3中已经没有cmp函数,被operator模块代替,在交互模式下使用时,需要导入模块。

在没有导入模块情况下,会出现

提示找不到cmp函数了,那么在python3中该如何使用这个函数呢?

#内置函数
operator.lt(a, b)
operator.le(a, b)
operator.eq(a, b)
operator.ne(a, b)
operator.ge(a, b)
operator.gt(a, b)
operator.__lt__(a, b)
operator.__le__(a, b)
operator.__eq__(a, b)
operator.__ne__(a, b)
operator.__ge__(a, b)
operator.__gt__(a, b)

简单说明下这几个函数的意义:

#函数返回值为布尔型
#在返回 true的情况下
lt(a,b) 表示 a<b :从第一个数字或字母(ASCII)比大小 le(a,b) 表示 a<=b eq(a,b) 表示 a==b 字母完全一样,返回True, ne(a,b) 表示 a!=b gt(a,b) 表示 a>b ge(a,b) 表示 a>=b

python之operator模块的更多相关文章

  1. 【Python】operator 模块简单介绍

    简单介绍几个常用的函数,其他的请参考文档. operator.concat(a, b) **operator.__concat__(a, b)** 对于 a.b序列,返回 a + b(列表合并) -- ...

  2. Python第十一天 异常处理 glob模块和shlex模块 打开外部程序和subprocess模块 subprocess类 Pipe管道 operator模块 sorted函数 os模块 hashlib模块 platform模块 csv模块

    Python第十一天    异常处理  glob模块和shlex模块    打开外部程序和subprocess模块  subprocess类  Pipe管道  operator模块   sorted函 ...

  3. Python中使用operator模块实现对象的多级排序

    Python中使用operator模块实现对象的多级排序 今天碰到一个小的排序问题,需要按嵌套对象的多个属性来排序,于是发现了Python里的operator模块和sorted函数组合可以实现这个功能 ...

  4. Python标准库笔记(11) — Operator模块

    Operator--标准功能性操作符接口. 代码中使用迭代器时,有时必须要为一个简单表达式创建函数.有些情况这些函数可以用一个lambda函数实现,但是对于某些操作,根本没必要去写一个新的函数.因此o ...

  5. python标准库介绍——8 operator 模块详解

    ==operator 模块== ``operator`` 模块为 Python 提供了一个 "功能性" 的标准操作符接口. 当使用 ``map`` 以及 ``filter`` 一类 ...

  6. Python基础学习:operator模块

    operator——函数的标准操作 转自:https://blog.csdn.net/zhtysw/article/details/80510113 代码资源:Lib/operator.py oper ...

  7. operator模块

    # -*- coding: utf-8 -*- # ==================== #File: python #Author: python #Date: 2014 #========== ...

  8. python的operator.itemgetter('click')用于定义获取'click'项的函数

    python的排序参见文章http://blog.csdn.net/longshenlmj/article/details/12747195 这里介绍 import operator模块 operat ...

  9. Python第八天 模块 包 全局变量和内置变量__name__ Python path

    Python第八天  模块   包   全局变量和内置变量__name__    Python path 目录 Pycharm使用技巧(转载) Python第一天  安装  shell  文件 Pyt ...

随机推荐

  1. laravel中Blade模板继承

    Blade模板继承 和 区块 <!-- 文件保存于 resources/views/layouts/app.blade.php --> <html> <head> ...

  2. UIView常用属性与方法/UIKit继承结构

    UIView常用属性与方法 @interface UIView : UIResponder<NSCoding, UIAppearance, UIAppearanceContainer, UIDy ...

  3. 自适应process组件

    很久没有写博客了,自从工作忙了就忘了学习新东西,真是越大越懒. 做项目中,需要一个process流程的UI组件,翻遍公司组件和业界框架,都没有满足自适应要求的现成的process组件,只能自己实现.实 ...

  4. ng 变量和常量服务

    <!DOCTYPE html> <html ng-app="myApp"> <head lang="en"> <met ...

  5. 几个Unity3d UI制作的解决方案.

    1.ex2D的渲染机制 (高效的原因) 在以往的2D插件中,渲染方式是每个sprite单独渲染,由Unity负责Dynamic Batching.在新版ex2D中,我们经过严谨的优化实现了独立的dyn ...

  6. 【MFC】SetWindowPos函数使用详解

    摘自: http://wenku.baidu.com/link?url=hYKs20rYA13TTdMl9gJ378GNOsxH1DPZPkYZVEIcipATlVBMLzjWdpd2-29fm-tq ...

  7. C语言 产生随机数

    rand()函数 #include <stdlib.h> int rand(void); rand()是根据某个种子,以特定的算法,计算出一系列数的函数.返回的数在0和RAND_MAX之间 ...

  8. .NET程序如何启动?

    .net程序如何启动? .NET Framework在Windows平台顶部运行,这意味着.NET Framework必须使用 windows可以理解的技术来构建.首先,所有托管模块和程序集文件都必须 ...

  9. STM32GPIO管脚设置

    (1)GPIO_Mode_AIN 模拟输入 (2)GPIO_Mode_IN_FLOATING 浮空输入(3)GPIO_Mode_IPD 下拉输入 (4)GPIO_Mode_IPU 上拉输入 (5)GP ...

  10. Eclipse 进入前选择Workspace

    如果选择了默认的Workspace会有一个问题. 打开一个workspace的时候,再次打开eclipse会报错,提示当前workspace正在被使用,然后让选择workspace. 最好的方法是每次 ...