0d: 00h: 00m: 00s

🎁 Get 3 extra months of learning — completely FREE

That's 90 extra days to master new skills, build more projects, and land your dream job.

Become a PRO
Background Image

🎁 Get 3 extra months of learning completely FREE

Become a PRO
Udayan Shakya's profileExpert

Udayan Shakya

Technical Content Writer @Programiz

Answered 1 questions


About

Answered by Udayan Shakya
U
Expert
last week
Udayan Shakya answered

Hi Alan, that’s a great question.

In Python, powers work a little differently from what you see on most calculators. Calculators usually use the ^ symbol for exponents, so it’s normal to try the same thing in Python. The tricky part is that Python doesn’t use ^ for powers at all, so it won’t give the result you expect.

The Python way to calculate a power is with two stars. So if you want “4 to the power of 3,” you write:

4 ** 3

Python reads that as “multiply 4 by itself three times,” which gives:

4 * 4 * 4 = 64

You can do the same with decimals:

2.5 ** 3   # 15.625

Once you get used to **, it becomes pretty straightforward.

If you have more questions while you’re learning, I’m happy to help.

Python
This question was asked as part of the Learn Python Basics course.