python math模块中的sqrt()函数使用方法

3,253次阅读
没有评论

python

python中有很多的内置函数,这些函数能实现特定的功能,而不需要重新定义函数。下面看一个math模块中的sqrt()函数。

sqrt() 方法返回数字x的平方根

以下是 sqrt() 方法的语法:

import math
math.sqrt( x )

注意:sqrt()是不能直接访问的,需要导入 math 模块,通过静态对象调用该方法。

参数,x — 数值表达式。

返回值,返回数字x的平方根。

python math模块中的sqrt()函数实例

#!/usr/bin/python
import math   # This will import math module

print "math.sqrt(100) : ", math.sqrt(100)
print "math.sqrt(7) : ", math.sqrt(7)
print "math.sqrt(math.pi) : ", math.sqrt(math.pi)

返回结果

math.sqrt(100) :  10.0
math.sqrt(7) :  2.64575131106
math.sqrt(math.pi) :  1.77245385091
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试

相关文章:

版权声明:wuyou2019-09-30发表,共计488字。
新手QQ群:570568346,欢迎进群讨论 Python51学习
评论(没有评论)