python mathpow
时间: 2023-09-14 20:05:02 浏览: 128
python中pow函数用法及功能说明
5星 · 资源好评率100%
The math.pow() function in Python returns the value of x raised to the power of y. The syntax of the function is as follows:
math.pow(x, y)
Here, x is the base and y is the exponent. The function returns a float value.
Example:
To calculate the value of 3 raised to the power of 2, we can use the math.pow() function as follows:
import math
result = math.pow(3, 2)
print(result)
Output:
9.0
In this example, we have imported the math module and used the pow() function to calculate 3^2, which is 9. The result is stored in the variable 'result' and then printed to the console.
阅读全文