What does ** mean in python?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
ROSELJR
Posts: 1
Joined: Sat Oct 09, 2021 4:20 am

What does ** mean in python?

Post by ROSELJR » Tue Oct 12, 2021 2:22 am

radius = 5
pi = 3.14159
volume = 4.0/3 * pi * radius ** 3

print "The volume is", volume

Output result:
[root@localhost t]$ python pi.py

The volume is 523.598333333 How did this 523.598333333 come from? And what does ** mean in python?

davef
Posts: 811
Joined: Thu Apr 30, 2020 1:03 am
Location: Christchurch, NZ

Re: What does ** mean in python?

Post by davef » Tue Oct 12, 2021 5:23 am

Working backwards it looks like radius **3 means radius * 3 * 3 * 3 or radius * 9. Is that the same as radius ^ 3?
https://careerkarma.com/blog/python-power/

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: What does ** mean in python?

Post by pythoncoder » Tue Oct 12, 2021 9:54 am

In the context of a mathematical expression it is raising to a power. Thus 2**8 == 256. The ** construct in Python has other meanings in different contexts.
Peter Hinch
Index to my micropython libraries.

Post Reply