Python math.isqrt() – Integer Square Root of a Number

Python math.isqrt()

math.isqrt(x) function returns the integer square root of non-negative integer x.

The return value of isqrt(x) is equivalent to the floor of sqrt(x).

Syntax

The syntax to call isqrt() function is

math.isqrt(x)

where

Parameter Required Description
x Yes A non-negative integer.

Examples

1. Find the square root of an integer value

In the following program, we find the square root of an integer value 11.

Python Program

import math

x = 11
result = math.isqrt(x)
print('isqrt(x) :', result)
Run Code

Output

isqrt(x) : 3

2. Find the square root of a float value

Since isqrt() accepts only integer value, if float value is passed as argument to it, the function raises TypeError.

Python Program

import math

x = 11.5
result = math.isqrt(x)
print('isqrt(x) :', result)
Run Code

Output

TypeError: 'float' object cannot be interpreted as an integer

Summary

In this Python Math tutorial, we learned the syntax of, and examples for math.isqrt() function.

Related Tutorials

Privacy Policy Terms of Use

SitemapContact Us