Python math.isqrt() Method
Python math.isqrt(x) The method returns the square root of x, rounded down to the nearest integer.
The number must be greater than or equal to 0.
Python version: 3.8
Syntax
The syntax of the math.isqrt() method is as follows:
math.isqrt(x)
Parameter Description:
- x -- required, a number. If x is not a number, a TypeError is returned. If the number is less than 0, a ValueError is returned.
Return Value
Returns an integer int representing the square root of a number, rounded down to the nearest integer.
Example
The following example returns the square root of numbers, rounded down to the nearest integer:
Example
Import the math package
import
math
Output the square root
Print the square root of different numbers
(
math
.
sqrt
(
10
)
)
(
math
.
sqrt
(
12
)
)
(
math
.
sqrt
(
68
)
)
(
math
.
sqrt
(
100
)
)
Output the square root, rounded down to the nearest integer
(
math
.
isqrt
(
10
)
)
(
math
.
isqrt
(
12
)
)
(
math
.
isqrt
(
68
)
)
(
math
.
isqrt
(
100
)
)
Output result:
3.1622776601683795
3.4641016151377544
8.246211251235321
10.0
3
3
8
10
Python math Module