Python – Find values Close to Each Other – isclose() Function with Examples

isclose() function is used to find the True if the values a and b are close to each other and False otherwise in Python for the given input(x – parameter).

 

Syntax of isclose() Function

The syntax of isclose() function in Python is:

math.isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0)

 

Parameters of isclose() Function in Python

x – Where x is any valid python number (positive or negative). This parameter is required.
Note: If the x parameter is not a number, isclose() function will return an Error.

 

Compatibility

isclose() function is available and compatible with Python 3.5 and above versions. This function is a part of python standard math library.

 

Return Value of isclose() Function in Python

isclose() function returns True if the values a and b are close to each other and False otherwise for the given input.

 

Python isclose() Function Example

# import math library
import math
print(math.isclose(-0.2))
print(math.isclose(0))
print(math.isclose(0.2))
print(math.isclose(77))
print(math.isclose(-3677))

Output: