The operator
module supplies functions that are
equivalent to Python’s operators. These functions
are handy for use with map
and
reduce
, and in other cases where callables must be
stored, passed as arguments, or returned as function results. The
functions in operator
have the same names as the
corresponding special methods (covered in Chapter 5). Each function is available with two names,
with and without the leading and trailing double underscores (e.g.,
both
operator.add(
a
,b
)
and operator.__add__(
a
,b
)
return
a
+
b
).
Table 151 lists the functions supplied by
operator
.
Table 151. Functions supplied by operator
Method 
Signature 
Behaves like 

abs 
abs(


add 
add( 

and_ 
and_( 

concat 
concat( 

contains 
contains( 

countOf 
countOf( 

delitem 
delitem( 

delslice 
delslice( 

div 
div( 

getitem 
getitem( 

getslice 
getslice( 

indexOf 
indexOf( 

invert, inv 


lshift 
lshift( 

mod 
mod( 

mul 
mul( 

neg 
neg(


not_ 
not_(


or_ 
or_( 

pos 
pos(


repeat 
repeat( 

rshift 
rshift( 

setitem 
setitem( 

setslice 
setslice( 

sub 
sub( 

No credit card required