How to express power in Python

silencement
Release: 2019-05-22 13:13:18
Original
58753 people have browsed it

Everyone knows that Python can be used to do data calculations, so how to express exponentiation in Python?

How to express power in Python

Look at the following example:

To calculate the results of 4 * 4 and 5 * 5, you can write like this

How to express power in Python

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

How to express power in Python

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

How to express power in Python

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template