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

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

技术教程推荐

如何设计一个秒杀系统 -〔许令波〕

TensorFlow快速入门与实战 -〔彭靖田〕

零基础学Java -〔臧萌〕

全栈工程师修炼指南 -〔熊燚(四火)〕

Selenium自动化测试实战 -〔郭宏志〕

To B市场品牌实战课 -〔曹林〕

分布式金融架构课 -〔任杰〕

手把手带你写一个Web框架 -〔叶剑峰〕

深入浅出分布式技术原理 -〔陈现麟〕

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