💾 Archived View for tris.fyi › pydoc › operator captured on 2023-04-26 at 13:30:58. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2022-07-16)

-=-=-=-=-=-=-

Back to module index

Go to module by name

operator

Operator interface.

This module exports a set of functions implemented in C corresponding
to the intrinsic operators of Python.  For example, operator.add(x, y)
is equivalent to the expression x+y.  The function names are those
used for special methods; variants without leading and trailing
'__' are also provided for convenience.

Classes

attrgetter

attrgetter(attr, ...) --> attrgetter object

Return a callable object that fetches the given attribute(s) from its operand.
After f = attrgetter('name'), the call f(r) returns r.name.
After g = attrgetter('name', 'date'), the call g(r) returns (r.name, r.date).
After h = attrgetter('name.first', 'name.last'), the call h(r) returns
(r.name.first, r.name.last).

itemgetter

itemgetter(item, ...) --> itemgetter object

Return a callable object that fetches the given item(s) from its operand.
After f = itemgetter(2), the call f(r) returns r[2].
After g = itemgetter(2, 5, 3), the call g(r) returns (r[2], r[5], r[3])

methodcaller

methodcaller(name, ...) --> methodcaller object

Return a callable object that calls the given method on its operand.
After f = methodcaller('name'), the call f(r) returns r.name().
After g = methodcaller('name', 'date', foo=1), the call g(r) returns
r.name('date', foo=1).

Functions

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 items in a which are, or which equal, b.

delitem

delitem(a, b, /)

  Same as del a[b].

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].

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.

ifloordiv

ifloordiv(a, b, /)

  Same as a //= b.

ilshift

ilshift(a, b, /)

  Same as a <<= b.

imatmul

imatmul(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.

irshift

irshift(a, b, /)

  Same as a >>= b.

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.

ixor

ixor(a, b, /)

  Same as a ^= b.

le

le(a, b, /)

  Same as a <= b.

length_hint

length_hint(obj, default=0, /)

  Return an estimate of the number of items in obj.

  This is useful for presizing containers when building from an iterable.

  If the object supports len(), the result will be exact.
  Otherwise, it may over- or under-estimate by an arbitrary amount.
  The result will be an integer >= 0.

lshift

lshift(a, b, /)

  Same as a << b.

lt

lt(a, b, /)

  Same as a < b.

matmul

matmul(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.

rshift

rshift(a, b, /)

  Same as a >> b.

setitem

setitem(a, b, c, /)

  Same as a[b] = c.

sub

sub(a, b, /)

  Same as a - b.

truediv

truediv(a, b, /)

  Same as a / b.

truth

truth(a, /)

  Return True if a is true, False otherwise.

xor

xor(a, b, /)

  Same as a ^ b.