Python3 sqrt() 函数

Python 3 教程 · 2019-02-05 14:57:31

描述

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

语法

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

import math

math.sqrt( x )

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

参数

  • x -- 数值表达式。

返回值

返回数字x的平方根。

实例

以下展示了使用 sqrt() 方法的实例:

#!/usr/bin/python3
import math   # 导入 math 模块

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.6457513110645907
math.sqrt(math.pi) :  1.7724538509055159

点击查看所有 Python 3 教程 文章: https://codercto.com/courses/l/10.html

查看所有标签

Programming From The Ground Up

Programming From The Ground Up

Jonathan Bartlett / Bartlett Publishing / 2004-07-31 / USD 34.95

Programming from the Ground Up is an introduction to programming using assembly language on the Linux platform for x86 machines. It is a great book for novices who are just learning to program as wel......一起来看看 《Programming From The Ground Up》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

随机密码生成器
随机密码生成器

多种字符组合密码

html转js在线工具
html转js在线工具

html转js在线工具