Python Programming/Math

For basic math including addition, subtraction, multiplication and the like, see ../Basic Math/ and ../Operators/ chapters. For quick reference, the built-in Python math operators include addition (+), subtraction (-), multiplication (*), division (/), floor division (//), modulo (%), and exponentiation (**). The built-in Python math functions include rounding (round), absolute value (abs), minimum (min), maximum (max), division with a remainder (divmod), and exponentiation (pow). Sign function can be created as "sign = lambda n: 1 if n > 0 else -1 if n < 0 else 0".

Math
A range of mathematical functions is available from math module of the standard library:

Example code using in-built operators
This code was made to replicate the log function in a calculator

Cmath
The cmath module provides similar functions like the math module but for complex numbers, and then some.

Random
Pseudo-random generators are available from the random module:

Decimal
The decimal module enables decimal floating point arithmethic, avoiding certain artifacts of the usual underlying binary representation of floating point numbers that are unintuitive to humans.

Fractions
The fractions module provides fraction arithmetic via Fraction class. Compared to floating point numbers representing fractions, Fraction fractions do not lose precision.

Statistics
The statistics module, available since Python 3.4, provides some basic statistical functions. It only provides basics; it does not replace full-fledged 3rd party libraries such as numpy. For Python 2.7, the statistics module can be installed from pypi.