Operators
** — Exponentiation
Raises the base to the exponent. Nonnegative integer exponents on integer bases yield integers, whereas negative integer exponents yield floats. A negative real base with a nonintegral exponent may produce a complex result. Zero raised to a negative power raises ZeroDivisionError. ** groups from right to left; -2**2 means -(2**2), but 2**-2 is valid. __pow__ and __rpow__ provide custom behavior. For modular exponentiation use three-argument pow().
Formal Syntax & Structure
python syntaxpython
left ** rightParameters & Attributes
| Name | Type | Description |
|---|---|---|
| left | number or supporting object | Base to raise to a power. |
| right | number or supporting object | Exponent; negative and fractional cases have additional constraints. |
Return Value
number or custom result
Numeric result for supported built-in numbers; custom methods can return other objects.
Working Example
Example Snippetpython
print(2 ** 5)print(2 ** 3 ** 2)print(-2 ** 2)print(2 ** -2)