python之operator模块
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模块的更多相关文章
- 【Python】operator 模块简单介绍
简单介绍几个常用的函数,其他的请参考文档. operator.concat(a, b) **operator.__concat__(a, b)** 对于 a.b序列,返回 a + b(列表合并) -- ...
- Python第十一天 异常处理 glob模块和shlex模块 打开外部程序和subprocess模块 subprocess类 Pipe管道 operator模块 sorted函数 os模块 hashlib模块 platform模块 csv模块
Python第十一天 异常处理 glob模块和shlex模块 打开外部程序和subprocess模块 subprocess类 Pipe管道 operator模块 sorted函 ...
- Python中使用operator模块实现对象的多级排序
Python中使用operator模块实现对象的多级排序 今天碰到一个小的排序问题,需要按嵌套对象的多个属性来排序,于是发现了Python里的operator模块和sorted函数组合可以实现这个功能 ...
- Python标准库笔记(11) — Operator模块
Operator--标准功能性操作符接口. 代码中使用迭代器时,有时必须要为一个简单表达式创建函数.有些情况这些函数可以用一个lambda函数实现,但是对于某些操作,根本没必要去写一个新的函数.因此o ...
- python标准库介绍——8 operator 模块详解
==operator 模块== ``operator`` 模块为 Python 提供了一个 "功能性" 的标准操作符接口. 当使用 ``map`` 以及 ``filter`` 一类 ...
- Python基础学习:operator模块
operator——函数的标准操作 转自:https://blog.csdn.net/zhtysw/article/details/80510113 代码资源:Lib/operator.py oper ...
- operator模块
# -*- coding: utf-8 -*- # ==================== #File: python #Author: python #Date: 2014 #========== ...
- python的operator.itemgetter('click')用于定义获取'click'项的函数
python的排序参见文章http://blog.csdn.net/longshenlmj/article/details/12747195 这里介绍 import operator模块 operat ...
- Python第八天 模块 包 全局变量和内置变量__name__ Python path
Python第八天 模块 包 全局变量和内置变量__name__ Python path 目录 Pycharm使用技巧(转载) Python第一天 安装 shell 文件 Pyt ...
随机推荐
- laravel中Blade模板继承
Blade模板继承 和 区块 <!-- 文件保存于 resources/views/layouts/app.blade.php --> <html> <head> ...
- vs2013出现错误提示error C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s
这个问题是vs准备弃用strcpy带来的,因为觉得他不太安全 可以尝试在main函数前面加上#pragma warning(disable:4996)即可解决这个问题
- mysql中delete的表别名使用方法
在 mapper.xml 中的 dynamicWhere 动态查询中使用了表别名,Delete 语句引用了动态查询,如下: <delete id="delete" param ...
- Unity3d command line arguments
Options Many of these relate to Unity3d command line arguments Batch Mode - should be left enabled u ...
- Android WebView remote debugging
/***************************************************************************** * Android WebView rem ...
- I.MX6 ethtool 移植
/************************************************************************* * I.MX6 ethtool 移植 * 说明: ...
- 【MFC】如何在MFC创建的程序中更改主窗口的属性 与 父窗口 WS_CLIPCHILDREN 样式 对子窗口刷新的影响 与 窗体区域绘制问题WS_CLIPCHILDREN与WS_CLIPSIBLINGS
如何在MFC创建的程序中更改主窗口的属性 摘自:http://blog.sina.com.cn/s/blog_4bebc4830100aq1m.html 在MFC创建的单文档界面中: (基于对话框的, ...
- UltraEdit工具安装和注册机破解
1.关闭网络连接(或者直接拔掉网线). 2.打开UltraEdit软件,稍等片刻会出现提示你你使用的是试用版本的窗口.如下图,点击“注册”. 3.填写许可证id和密码.许可证id可任意填写,不过根据经 ...
- AngularJS方法 —— angular.bootstrap
描述: 此方法用于手动加载angularjs模板 (官方翻译:注意基于端到端的测试不能使用此功能来引导手动加载,他们必须使用ngapp. angularjs会检测这个模板是否被浏览器加载或者加载多次并 ...
- LibreOJ β Round #2 题解
LibreOJ β Round #2 题解 模拟只会猜题意 题目: 给定一个长为 \(n\) 的序列,有 \(m\) 次询问,每次问所有长度大于 \(x\) 的区间的元素和的最大值. \(1 \leq ...