Python sqrt() 函数

栏目: 编程语言 · Python · 编程教程 · python 教程 · 发布时间: 8年前

内容简介:sqrt() 方法返回数字x的平方根。

描述

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

语法

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

import math

math.sqrt( x )

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

参数

  • x -- 数值表达式。

返回值

返回数字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

以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

The Shallows

The Shallows

Nicholas Carr / W. W. Norton & Company / 2010-6-15 / USD 26.95

"Is Google making us stupid?" When Nicholas Carr posed that question, in a celebrated Atlantic Monthly cover story, he tapped into a well of anxiety about how the Internet is changing us. He also crys......一起来看看 《The Shallows》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

URL 编码/解码
URL 编码/解码

URL 编码/解码