Home > Backend Development > Python Tutorial > How to use the sqrt function in Python

How to use the sqrt function in Python

爱喝马黛茶的安东尼
Release: 2019-06-26 13:32:25
Original
14894 people have browsed it

How to use the sqrt function in Python

How to use the sqrt function in Python? The following is an introduction to the sqrt function:

The Python number sqrt() function returns the square root of x (x > 0).

Syntax

The following is the syntax of the sqrt() method-

import math
math.sqrt( x )

Note - This function is not directly accessible, you need to import the math module, and then you need to use the math static object to call this function.

Parameters

x - This is a numeric expression.

Return value

This method returns the square root of x (x > 0).

sqrt() method returns the square root of the number x.

Related recommendations: "Python Video Tutorial"

Example

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))
Copy after login

The output result after running the above example is :

math.sqrt(100) :  10.0
math.sqrt(7) :  2.6457513110645907
math.sqrt(math.pi) :  1.7724538509055159
Copy after login

The above is the detailed content of How to use the sqrt function in Python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template