python math数学函数

python math.pow(x,y)函数用于计算x的y次方。

语法

语法如下:
import math #导入math模块
math.pow( x,y )

参数

  • x: x为底数
  • y: y为指数

返回值

返回x的y次方。

程序示例

#!/usr/bin/python
# coding=utf-8
import math
print(math.pow(2,3)) #2的3次方
print(math.pow(1,3)) #1的3次方
print(math.pow(-1,3))#-1的3次方
print(math.pow(2,3))#2的3次方 

程序运行结果:

8.0
1.0
-1.0
8.0