Python math.isfinite() Method
Python math.isfinite() The method determines whether x is finite, returning True if x is neither infinity nor NaN, otherwise False.
Python version: 3.2
Syntax
The syntax of the math.isfinite() method is as follows:
math.isfinite(x)
Parameter Description:
- x -- required, a number. If x is not a number, a TypeError is returned.
Return Value
Returns a Boolean; True if x is neither infinity nor NaN, otherwise False.
Example
The following example checks whether numbers are finite:
Example
Import the math package
import
math
Check whether a number is finite
(
math
.
isfinite
(
2000
)
)
(
math
.
isfinite
(
45.34
)
)
(
math
.
isfinite
(
45.34
)
)
(
math
.
isfinite
(
math
.
inf
)
)
(
math
.
isfinite
(
float
(
"nan"
)
)
)
(
math
.
isfinite
(
float
(
"inf"
)
)
)
(
math
.
isfinite
(
float
(
"-inf"
)
)
)
(
math
.
isfinite
(
math
.
inf
)
)
(
math
.
isfinite
(
0.0
)
)
Output result:
True
True
True
False
False
False
False
False
True
Python math Module