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?
What does ** mean in python?
Re: What does ** mean in python?
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/
https://careerkarma.com/blog/python-power/
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: What does ** mean in python?
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.
Index to my micropython libraries.