**

Real exponentiation — 2 ** 10 is 1024, and the ^ you might reach for is XOR.

Arithmetic operatorPython 1.0+Live demo
Common call
2 ** 10
Returns
int for int ** non-negative int, float otherwise
Replaces
right-associative: 2 ** 3 ** 2 is 2 ** 9 = 512
Watch out
2 ^ 10 is 8 — that is XOR, not power
aaBase.type: number · required ** bbExponent — negative gives a float, fractional gives roots.type: number · required
number

Demo

Live evaluation
Try:
Inputs
afloatbase
bfloatexponent
Output
2 ** 10
1024

Negative exponents flip into fractions (2 ** -1 is 0.5) and fractional exponents take roots (9 ** 0.5 is 3.0). Zero to a negative power raises Python’s exact error.

Operands

NameTypeRequiredDescription
anumberyesBase.
bnumberyesExponent — negative gives a float, fractional gives roots.

Return value

numbera raised to the power b. Negative exponents produce floats; int ** positive-int stays exact int.

Common patterns

Squares and roots
** 0.5 is the idiomatic quick square root.
dist = (dx**2 + dy**2) ** 0.5
Powers of two
Sizes, limits, bit-work — exact big ints included.
max_int64 = 2 ** 63 - 1
Modular exponentiation
The three-argument pow() built-in is far faster than ** then %.
pow(base, exp, modulus)   # crypto-sized numbers

Examples

1. Integer power
2 ** 10
Returns
1024
2. Negative exponent
2 ** -1
Returns
0.5
3. Square root
9 ** 0.5
Returns
3.0
4. Right associativity
2 ** 3 ** 2
Returns
512

Pitfalls

1. ^ is XOR, not power
The single caret is bitwise exclusive-or — a silent, wildly different result.
Silent wrong answer
2 ^ 10
8
Fix
2 ** 10
1024
2. Right-associative chains
2 ** 3 ** 2 groups as 2 ** (3 ** 2) — unlike most operators.
Expected 64?
2 ** 3 ** 2
512
Parenthesize intent
(2 ** 3) ** 2
64
3. Unary minus binds looser
-2 ** 2 is -(2 ** 2), not (-2) ** 2.
Surprising
-2 ** 2
-4
Fix
(-2) ** 2
4

When to use

Use it
  • Exact integer powers (arbitrary precision)
  • Quick roots via fractional exponents
  • Readable squared/cubed math
Reach for something else
  • Modular exponentiation → pow(a, b, m)
  • Heavy float math → math.pow / math.sqrt (clearer intent)
  • Bit flips → that IS ^ (bitwise XOR)

Notes

Complexity
O(log b) multiplications for int powers
Return
int stays exact; negative/fractional exponents give float
CPython impl
Objects/abstract.c :: PyNumber_Power → __pow__
Memory
Big int powers allocate as needed — 2**10000 is fine
Thread-safe
Yes — pure computation

FAQ

Convention from mathematics: a^(b^c) is the useful reading of stacked exponents, so Python groups from the right.

History

1.0
Core operator from the beginning.