Python Tutorial Python Advanced Python References Python Libraries

Python math - isfinite() Function



The Python math.isfinite() function is used to check if the argument is a finite number or not. It returns true if the argument is neither an infinity nor a NaN, else returns false.

Syntax

math.isfinite(x)   

Parameters

x Required. Specify the value.

Return Value

Returns true if the argument is neither an infinity nor a NaN, else returns false.

Example:

In the example below, isfinite() function is used to check if the argument is a finite number or not.

import math

print(math.isfinite(2))
print(math.isfinite(-2))
print(math.isfinite(1.5),"\n")

print(math.isfinite(float("nan")))
print(math.isfinite(float("inf")))
print(math.isfinite(float("-inf")))

The output of the above code will be:

True
True
True

False
False
False

❮ Python Math Module

5