Easy Tutorial
❮ Ref Math Gcd Python File Close ❯

Python math.isqrt() Method

Python math Module

The math.isqrt(x) method in Python 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 for the math.isqrt() method is as follows:

math.isqrt(x)

Parameter:

Return Value

Returns an integer, representing the square root of a number, rounded down to the nearest integer.

Example

The following example returns the square root of a number, rounded down to the nearest integer:

Example

# Import math package
import math

# Print the square root of different numbers
print(math.sqrt(10))
print(math.sqrt(12))
print(math.sqrt(68))
print(math.sqrt(100))

# Print the square root, rounded down to the nearest integer
print(math.isqrt(10))
print(math.isqrt(12))
print(math.isqrt(68))
print(math.isqrt(100))

Output:

3.1622776601683795
3.4641016151377544
8.246211251235321
10.0
3
3
8
10

Python math Module

❮ Ref Math Gcd Python File Close ❯