In Python math module,
math.isclose() method is used to determine whether two floating point numbers are close in value. For using this function you must import math module.
Syntax: isclose(a, b, rel_tol = 1e-09, abs_tol 0.0)
rel_tol: maximum difference for being considered “close”, relative to the magnitude of the input values
abs_tol: maximum difference for being considered “close”, regardless of the magnitude of the input values
abs_tolcan be changed by using keyword argument, or by simply providing directly as according to their positions in the parameter list.
Return Value : Return True if a is close in value to b, and False otherwise.
Note: For the values to be considered close, the difference between them must be smaller than at least one of the tolerances.
True False False
True False True
You can change absolute tolerance, as in above case absolute tolerance is different in all three cases.
Reference: Python math library
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course