O'Reilly logo

Python: Essential Reference, Third Edition by David Beazley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

operator

The operator module provides functions that access the built-in operators and special methods of the interpreter described in Chapter 3. For example, add(3, 4) is the same as 3 + 4. When the name of a function matches the name of a special method, it can also be invoked using its name with double underscores—for example, __add__(3, 4).

FunctionDescription
add(a, b)Returns a + b for numbers
sub(a ,b)Returns a – b
mul(a, b)Returns a* b for numbers
div(a, b)Returns a / b(old division)
floordiv(a, b)Returns a // b
truediv(a ,b)Returns a / b(new division)
mod(a, b)Returns a % b
neg(a)Returns -a
pos(a)Returns +a
abs(a)Returns the absolute value of a
inv(a), invert(a)Returns the inverse of a(~a)
lshift(a, b)Returns a << b
rshift(a, b)Returns a >> b
and_(a, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required