all Python 3Arithmetic & operatorsterm
** exponentiation
arithmetic
The exponentiation operator. It is evaluated right to left (right-associative). It supports fractional exponents (roots) and negative ones.
Syntax
a ** b
Right-associativity matters more than it looks: 2 ** 3 ** 2 is 2 ** 9, that is 512, not 64. You get an int back only for a non-negative integer exponent — 2 ** -1 is the float 0.5, and a fractional power of a negative number lands in complex numbers. For modular arithmetic use pow(a, b, m); it is far faster than (a ** b) % m, which first builds a giant intermediate value.
Examples
print(2 ** 10) # → 1024
print(3 ** 3) # → 27
print(16 ** 0.5) # → 4.0 (квадратный корень)
print(27 ** (1/3)) # → 3.0 (кубический корень)
print(2 ** -1) # → 0.5 (отрицательная степень)
print(2 ** 100) # → большое число (Python big int)
See also
Open in the full glossarydocs.python.orgReport an inaccuracy