Python math.isfinite() Method
Python math.isfinite()The method determines whether x is finite. If x is neither infinity nor NaN, it returns True; otherwise, it returns False.
Python version: 3.2
Syntax
The syntax of the math.isfinite() method is as follows:
math.isfinite(x)
Parameter description:
- xx -- Required, a number. If x is not a number, returns TypeError.
Return Value
Returns a boolean value. If x is neither infinity nor NaN, it returns True; otherwise, it returns False.
Example
The following example checks whether the numbers are finite:
Example
# Import math package
import math
# Check whether the numbers are finite
print(math.isfinite(2000))
print(math.isfinite(-45.34))
print(math.isfinite(+45.34))
print(math.isfinite(math.inf))
print(math.isfinite(float("nan")))
print(math.isfinite(float("inf")))
print(math.isfinite(float("-inf")))
print(math.isfinite(-math.inf))
print(math.isfinite(0.0))
import math
# Check whether the numbers are finite
print(math.isfinite(2000))
print(math.isfinite(-45.34))
print(math.isfinite(+45.34))
print(math.isfinite(math.inf))
print(math.isfinite(float("nan")))
print(math.isfinite(float("inf")))
print(math.isfinite(float("-inf")))
print(math.isfinite(-math.inf))
print(math.isfinite(0.0))
Output result:
True True True False False False False False TrueOther extensions
Python math Module