Python isfinite

The Python isfinite function checks whether the given value is a finite number (Not an Infinity and Not a Number) or not. If it is an infinite number or Not a Number, then isfinite returns False otherwise, True, and its syntax is

math.isfinite(value)

Python isfinite example

In this example, we are using the isfinite function on both positive & negative numeric and decimal values. We have also used Python math.pi as the argument of this Mathematical function.

import math
 
print(math.isfinite(1))
 
print(math.isfinite(0.00))
 
print(math.isfinite(-10))
 
print(math.isfinite(-10.0052))
 
print(math.isfinite(math.pi))
True
True
True
True
True

In this Python isfinite example, we are passing the infinity and not a number values as the function arguments.

import math
 
print(math.isfinite(0/1))
 
print(math.isfinite(0.00/10))
 
print(math.isfinite(float('NaN')))
 
print(math.isfinite(float('inf')))
 
print(math.isfinite(float('-inf')))
 
print(math.isfinite(math.inf))
 
print(math.isfinite(-math.inf))
Python isfinite Function 2

About Suresh

Suresh is the founder of TutorialGateway and a freelance software developer. He specialized in Designing and Developing Windows and Web applications. The experience he gained in Programming and BI integration, and reporting tools translates into this blog. You can find him on Facebook or Twitter.