Returns the square root of a number.
Synopsis
import math
math.sqrt(number)
Description
sqrt lives in the math module, so the file needs import math before you use it.
Parameters
| Name | Meaning |
|---|---|
number |
A number that is zero or more. |
Return value
A float, even for a perfect square.
Example
import math
print(math.sqrt(16))
print(math.sqrt(2))
It prints:
4.0
1.4142135623730951
Common mistake
print(math.sqrt(16))
Python stops with:
NameError: name 'math' is not defined. Did you forget to import 'math'
The file is missing import math at the top.
See also
Last updated 2 weeks ago