Python math.isqrt() Method
Python math.isqrt(x)The method returns the square root of x, and rounds the square root 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:
- xx -- Required, a number. If x is not a number, it returns TypeError. If the number is less than 0, it returns ValueError.
Return Value
Returns an integer int representing the square root of a number, and rounds the square root down to the nearest integer.
Example
The following example returns the square root of a number, and rounds the square root down to the nearest integer:
Example
# Import the math package
import math
# Output the square root
# Print the square root of different numbers
print (math.sqrt(10))
print (math.sqrt (12))
print (math.sqrt (68))
print (math.sqrt (100))
# Output the square root, and round the square root down to the nearest integer
print (math.isqrt(10))
print (math.isqrt (12))
print (math.isqrt (68))
print (math.isqrt (100))
import math
# Output the square root
# Print the square root of different numbers
print (math.sqrt(10))
print (math.sqrt (12))
print (math.sqrt (68))
print (math.sqrt (100))
# Output the square root, and round the square root down to the nearest integer
print (math.isqrt(10))
print (math.isqrt (12))
print (math.isqrt (68))
print (math.isqrt (100))
Output result:
3.1622776601683795 3.4641016151377544 8.246211251235321 10.0 3 3 8 10Other Extensions
Python math Module