Easy Tutorial
❮ Python Os Lseek Python Func Reload ❯

Python math.isfinite() Method

Python math Module

The math.isfinite() method in Python checks if x is finite. It returns True if x is neither infinite nor NaN, otherwise it returns False.

Python Version: 3.2

Syntax

The syntax for the math.isfinite() method is as follows:

math.isfinite(x)

Parameter Description:

Return Value

Returns a Boolean value. It returns True if x is neither infinite nor NaN, otherwise it returns False.

Example

The following example checks if numbers are finite:

Example

# Import math package
import math

# Check if 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
True

Python math Module

❮ Python Os Lseek Python Func Reload ❯