python operator库_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.         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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值