math.sqrt()

Anonymous contributor's avatar
Anonymous contributor
Anonymous contributor's avatar
Anonymous contributor
Published Jun 22, 2021Updated Mar 17, 2024
Contribute to Docs

Returns the square root of numeric input x.

Syntax

math.sqrt(x)

If input x is a negative value, .sqrt() will return a ValueError: math domain error.

Example

Use math.sqrt() to return the square root of integer 5:

import math
print(math.sqrt(5))

The above code gives the following output:

2.23606797749979

Use math.sqrt() to return the square root of the float 5.5:

import math
print(math.sqrt(5.5))

The above code gives the following output:

2.345207879911715

Codebyte Example

Run the following example that uses the math.sqrt() function to understand its working:

us
Visit us
code
Hide code
Code
Output
Hide output
Hide output
Loading...

All contributors

Looking to contribute?

Learn Python on Codecademy