pythonmathoperatorsexponent

How do I do exponentiation in python?


def cube(number):
  return number^3
print cube(2)

I would expect cube(2) = 8, but instead I'm getting cube(2) = 1

What am I doing wrong?


Solution

  • ^ is the xor operator.

    ** is exponentiation.

    2**3 = 8