求冪
a, b = 2, 3
(a ** b)               # = 8
pow(a, b)              # = 8
import math
math.pow(a, b)         # = 8.0 (always float; does not allow complex results)
import operator
operator.pow(a, b)     # = 8
內建的 pow 和 math.pow 之間的另一個區別是內建的 pow 可以接受三個引數:
a, b, c = 2, 3, 2
pow(2, 3, 2)           # 0, calculates (2 ** 3) % 2, but as per Python docs,
                       #    does so more efficiently
特殊功能
函式 math.sqrt(x) 計算 x 的平方根。
import math
import cmath
c = 4
math.sqrt(c)           # = 2.0 (always float; does not allow complex results)
cmath.sqrt(c)          # = (2+0j) (always complex)
要計算其他根,例如立方根,請將數字增加到根的度數的倒數。這可以使用任何指數函式或運算子來完成。
 import math
 x = 8
 math.pow(x, 1/3) # evaluates to 2.0
 x**(1/3) # evaluates to 2.0
函式 math.exp(x) 計算 e ** x。
math.exp(0)  # 1.0
math.exp(1)  # 2.718281828459045 (e)
函式 math.expm1(x) 計算 e ** x - 1。當 x 很小時,這比 math.exp(x) - 1 具有更好的精度。
math.expm1(0)       # 0.0
math.exp(1e-6) - 1  # 1.0000004999621837e-06
math.expm1(1e-6)    # 1.0000005000001665e-06
# exact result      # 1.000000500000166666708333341666...