The operator Module
The operator
module supplies functions that are equivalent to Python’s operators. These functions are handy in 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 Special Methods). Each function is available with two names, with and without leading and trailing double underscores (e.g., both operator.add(
a
,
b
)
and operator._ _add_ _(
a
,
b
)
return a
+
b
). Table 15-1 lists the functions supplied by the operator
module.
Table 15-1. Functions supplied by the operator module
Method | Signature | Behaves like |
---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Module operator
also supplies two higher-order functions whose results are functions suitable ...
Get Python in a Nutshell, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.