温馨提示×

python次方用什么函数

九三
2251
2021-01-22 13:29:05
栏目: 编程语言

python次方用什么函数

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

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

pow()函数语法:

math.pow( x, y )

pow()函数使用方法:

import math # 导入 math 模块

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

print "pow(100, 2) : ", 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

pow(100, 2) : 10000

math.pow(100, -2) : 0.0001

math.pow(2, 4) : 16.0

math.pow(3, 0) : 1.0

0