ExpertUdayan Shakya
Technical Content Writer @Programiz
Answered 1 questions
About
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.
