python中如何求幂函数

python中可以使用pow函数求幂,具体方法如下:

pow():pow()函数的作用是返回x的y次方的值。

pow()函数语法:

math.pow( x, y )

pow()函数使用方法:

import math #导入math模块

print "math.pow(100, 2) : ", math.pow(100, 2)

print "math.pow(100, -2) : ", math.pow(100, -2)

print "math.pow(2, 4) : ", math.pow(2, 4)

print "math.pow(3, 0) : ", math.pow(3, 0)

输出结果为:

math.pow(100, 2) : 10000.0

math.pow(100, -2) : 0.0001

math.pow(2, 4) : 16.0

math.pow(3, 0) : 1.0

赞(0)
未经允许不得转载:主机测评网 » python中如何求幂函数
分享到: 更多 (0)