Python 中的 sqrt(x)函数

首页 / Python2入门教程 / Python 中的 sqrt(x)函数

Python sqrt()返回x>0的x的平方根。

sqrt(x) - 语法

import math

math.sqrt( x )
  • x  -  这是一个数值表达式。

sqrt(x) - 返回值

此方法返回x>0的x的平方根。

sqrt(x) - 示例

以下示例显示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

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

趣谈网络协议 -〔刘超〕

面试现场 -〔白海飞〕

技术面试官识人手册 -〔熊燚(四火)〕

Go 语言项目开发实战 -〔孔令飞〕

程序员的测试课 -〔郑晔〕

零基础入门Spark -〔吴磊〕

大数据经典论文解读 -〔徐文浩〕

全链路压测实战30讲 -〔高楼〕

JavaScript进阶实战课 -〔石川〕

好记忆不如烂笔头。留下您的足迹吧 :)