all Python 3mathterm
math.sqrt
power/root
Returns the square root of a number as a float. For an integer result use isqrt(). A negative number raises ValueError.
Syntax
math.sqrt(x)
The argument is converted to float first, so the root of a large integer is only approximate, and anything above roughly 1.8e308 raises OverflowError — math.isqrt (Python 3.8+) handles integers of any size. For the same reason a perfect-square test written as math.sqrt(n) ** 2 == n starts giving wrong answers on big values; compare math.isqrt(n) ** 2 with n instead.
Examples
import math
print(math.sqrt(4)) # → 2.0
print(math.sqrt(2)) # → 1.41421356...
print(math.sqrt(0)) # → 0.0
print(math.sqrt(100)) # → 10.0
print(math.sqrt(2.25)) # → 1.5
print(round(math.sqrt(3), 6)) # → 1.732051
See also
Open in the full glossarydocs.python.orgReport an inaccuracy