Skip to content
scipython.com

Q2.2.10Exponentiation gotcha

Explain why the following expression does not evaluate to 100.

>>> 10^2
8

Hint: Refer to the Python documentation for \emph{bitwise} operators.

Show solution

The ^ operator does not raise a number to another power (that is the ** operator). It is the bitwise xor operator, and in binary 10^2 is 1010 xor 0010 = 1000 which is 8 in decimal.