python operator计算模块

这个模块提供了一系列的函数操作。比如,operator.add(x, y)等于x+y

a = [1,2,3]
b = [5,6,7]
c = map(operator.mul, a, b)
c的值就为[5, 12, 21]

abs(...)
        abs(a) -- Same as abs(a).
   
    add(...)
        add(a, b) -- Same as a + b.
   
    and_(...)
        and_(a, b) -- Same as a & b.
   
    concat(...)
        concat(a, b) -- Same as a + b, for a and b sequences.
   
    contains(...)
        contains(a, b) -- Same as b in a (note reversed operands).
   
    countOf(...)
        countOf(a, b) -- Return the number of times b occurs in a.
   
    delitem(...)
        delitem(a, b) -- Same as del a[b].
   
    delslice(...)
        delslice(a, b, c) -- Same as del a[b:c].
   
    div(...)
        div(a, b) -- Same as a / b when __future__.division is not in effect.
   
    eq(...)
        eq(a, b) -- Same as a==b.
   
    floordiv(...)
        floordiv(a, b) -- Same as a // b.
   
    ge(...)
        ge(a, b) -- Same as a>=b.
   
    getitem(...)
        getitem(a, b) -- Same as a[b].
   
    getslice(...)
        getslice(a, b, c) -- Same as a[b:c].
   
    gt(...)
        gt(a, b) -- Same as a>b.
   
    iadd(...)
        iadd(a, b) -- Same as a += b.
   
    iand(...)
        iand(a, b) -- Same as a &= b.
   
    iconcat(...)
        iconcat(a, b) -- Same as a += b, for a and b sequences.
   
    idiv(...)
        idiv(a, b) -- Same as a /= b when __future__.division is not in effect.
   
    ifloordiv(...)
        ifloordiv(a, b) -- Same as a //= b.
   
    ilshift(...)
        ilshift(a, b) -- Same as a <<= b.
   
    imod(...)
        imod(a, b) -- Same as a %= b.
   
    imul(...)
        imul(a, b) -- Same as a *= b.
    index(...)
        index(a) -- Same as a.__index__()
   
    indexOf(...)
        indexOf(a, b) -- Return the first index of b in a.
   
    inv(...)
        inv(a) -- Same as ~a.
   
    invert(...)
        invert(a) -- Same as ~a.
   
    ior(...)
        ior(a, b) -- Same as a |= b.
   
    ipow(...)
        ipow(a, b) -- Same as a **= b.
   
    irepeat(...)
        irepeat(a, b) -- Same as a *= b, where a is a sequence, and b is an integer.
   
    irshift(...)
        irshift(a, b) -- Same as a >>= b.
   
    isCallable(...)
        isCallable(a) -- Same as callable(a).
   
    isMappingType(...)
        isMappingType(a) -- Return True if a has a mapping type, False otherwise.
   
    isNumberType(...)
        isNumberType(a) -- Return True if a has a numeric type, False otherwise.
   
    isSequenceType(...)
        isSequenceType(a) -- Return True if a has a sequence type, False otherwise.
   
    is_(...)
        is_(a, b) -- Same as a is b.
    is_not(...)
        is_not(a, b) -- Same as a is not b.
   
    isub(...)
        isub(a, b) -- Same as a -= b.
   
    itruediv(...)
        itruediv(a, b) -- Same as a /= b when __future__.division is in effect.
   
    ixor(...)
        ixor(a, b) -- Same as a ^= b.
   
    le(...)
        le(a, b) -- Same as a<=b.
   
    lshift(...)
        lshift(a, b) -- Same as a << b.
   
    lt(...)
        lt(a, b) -- Same as a<b.
   
    mod(...)
        mod(a, b) -- Same as a % b.
   
    mul(...)
        mul(a, b) -- Same as a * b.
   
    ne(...)
        ne(a, b) -- Same as a!=b.
   
    neg(...)
        neg(a) -- Same as -a.
   
    not_(...)
        not_(a) -- Same as not a.
   
    or_(...)
        or_(a, b) -- Same as a | b.
    pos(...)
        pos(a) -- Same as +a.
   
    pow(...)
        pow(a, b) -- Same as a ** b.
   
    repeat(...)
        repeat(a, b) -- Return a * b, where a is a sequence, and b is an integer.
   
    rshift(...)
        rshift(a, b) -- Same as a >> b.
   
    sequenceIncludes(...)
        sequenceIncludes(a, b) -- Same as b in a (note reversed operands; deprecated).
   
    setitem(...)
        setitem(a, b, c) -- Same as a[b] = c.
   
    setslice(...)
        setslice(a, b, c, d) -- Same as a[b:c] = d.
   
    sub(...)
        sub(a, b) -- Same as a - b.
   
    truediv(...)
        truediv(a, b) -- Same as a / b when __future__.division is in effect.
   
    truth(...)
        truth(a) -- Return True if a is true, False otherwise.
   
    xor(...)
        xor(a, b) -- Same as a ^ b.

时间: 2024-08-11 05:43:42

python operator计算模块的相关文章

python 下的crc16计算模块 XCRC16

又一次突然遇到用python处理modbus通信而需要crc16校验的问题,当时在百度上没找到,在google上找到了一个外国人开发的python包,结果安装好了之后发现校验的不正确(可能是使用的模式串不一样,xcrc16的模式串为0xa001),后来事情过去了就写了一个包弥补一下,xcrc16 的意思是 extend crc->xcrc ,也是我的第一个开源项目,如果大家使用程序遇到什么情况也麻烦通知我下,我会第一时间进行维护. 介绍: xcrc16 模块是为了解决crc16校验问题而写 目前

python,基于tkinter模块编写的根据经纬度计算两点间距离的应用程序

python的tkinter模块是用于编写GUI窗口程序的模块,使用起来非常方便,功能强大.基于tkinter模块,开发了一个输入两点经纬度计算输出距离(包括公里数和孤度数)的小程序,主要应用于地震台站地震报告编写.下面这段代码可以在python3.8上直接运行. import tkinter as tk import tkinter.messagebox from math import radians, cos, sin, asin, sqrt #定义由输入文本框获得台站及震源经纬度,计算距

python中os模块中文帮助

python中os模块中文帮助 python中os模块中文帮助文档文章分类:Python编程 python中os模块中文帮助文档 翻译者:butalnd 翻译于2010.1.7——2010.1.8,个人博客:http://butlandblog.appspot.com/ 注此模块中关于unix中的函数大部分都被略过,翻译主要针对WINDOWS,翻译速度很快,其中很多不足之处请多多包涵. 这个模块提供了一个轻便的方法使用要依赖操作系统的功能. 如何你只是想读或写文件,请使用open() ,如果你想

python时间处理模块 datetime time模块 deltetime模块

1 首先介绍time模块,因为简单 python 自带模块 本人使用time模块,只使用两个函数 time函数和sleep函数 import time a.     time.time()   函数 返回unix时间  常用作两个时间差的计算 b.     time.sleep()  休眠多久,精度为子秒(subsecond) In [90]: t1 = time.time() In [91]: t1 Out[91]: 1461400225.877932 In [92]: time.sleep(

Python中time模块详解

在Python中,与时间处理有关的模块就包括:time,datetime以及calendar.这篇文章,主要讲解time模块. 在开始之前,首先要说明这几点: 在Python中,通常有这几种方式来表示时间:1)时间戳 2)格式化的时间字符串 3)元组(struct_time)共九个元素.由于Python的time模块实现主要调用C库,所以各个平台可能有所不同. UTC(Coordinated Universal Time,世界协调时)亦即格林威治天文时间,世界标准时间.在中国为UTC+8.DST

python之OS模块(对文件or目录操作)

OS模块 os,语义为操作系统,包含普遍的操作系统功能,与具体的平台无关.python编程时,处理文件和目录这些操作,就比如说:显示当前目录下所有文件/删除某个文件/获取文件大小-- os模块不受平台限制,也就是说:当我们要在linux中显示当前命令时就要用到pwd命令,而Windows中cmd命令行下就要用到这个,例如:这时候我们使用python中os模块的os.path.abspath(name)功能,甭管是linux或者Windows都可以获取当前的绝对路径. 常见函数列表 os.name

PYTHON学习第二模块 python内置模块介绍

1 >>> import time 2 >>> time.time() 3 1491064723.808669 4 >>> # time.time()返回当前时间的时间戳timestamp(定义为从格林威治时间1970年01月01日00时00分00秒起至现在的总秒数)的方法,无参数 5 >>> time.asctime() 6 'Sun Apr 2 00:39:32 2017' 7 >>> # time.asctim

Python(六)-常用模块

目录: 1.模块介绍 2.time & datetime模块 3.rendom 4.os 5.sys 6.shutil 7.json & picle 8.shelve 9.xml处理 10.yaml处理 11.chonfigparser 12.hashlib 13.subprocess 14.logging模块 15.re正则表达式 第一章:模块介绍 模块,用一坨代码实现了某个功能的代码集合. 类似于函数式编程和面向过程编程,函数式编程则完成一个功能,其他代码用来调用即可,提供了代码的重用

python基础之模块二

六 logging模块 6.1 函数式简单配置 import logging #导入模块 logging.debug('debug message') #调试消息 logging.debug('info message') #导入消息 logging.debug('warning message') #警告消息 logging.error('error message') #错误消息 logging.critical('critical message') #严重信息 默认情况下python的l