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 ** right

Parameters & Attributes

NameTypeDescription
leftnumber or supporting objectBase to raise to a power.
rightnumber or supporting objectExponent; 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)
Python Reference