Home >Backend Development >Python Tutorial >How to express power in Python
Everyone knows that Python can be used to do data calculations, so how to express exponentiation in Python?
Look at the following example:
To calculate the results of 4 * 4 and 5 * 5, you can write like this
As you can see, the output results are 16 and 25 respectively. If we want to calculate the multiplication of 4*4*4*4, or the multiplication of 2*2*2*2*2*2*2, it is very cumbersome to use the above method. How can we achieve it?
Here we can use exponentiation!
In Python, ** is used to represent exponentiation (there is no space between the two asterisks). With exponentiation, no matter how many identical numbers are multiplied, it can be easily done. solved!
Look at the following example
What is the result of calculating 4*4*4*4
As you can see, Python directly The result of 4 raised to the 4th power is given, and the result is 256
Look at another example: Calculate the 30th power of 2
Similarly, Python gives accurate results! Compared with the first example, using exponentiation greatly improves calculation efficiency, saves time, and the code is simpler and clearer!
The above is the detailed content of How to express power in Python. For more information, please follow other related articles on the PHP Chinese website!