Python math.isinf() - Check if Number is Infinity
Python math.isinf()
math.isinf(x) function returns True if x is either positive infinity or negative infinity, and False otherwise.
Syntax
The syntax to call isinf() function is
math.isinf(x)where
| Parameter | Required | Description |
|---|---|---|
| x | Yes | A numeric value. |
Examples
1. Check if positive infinity is infinity
Assign x with positive infinity, and programmatically check if x is infinity value, using math.isinf().
Python Program
import math
x = math.inf
result = math.isinf(x)
print('isinf(x) :', result)Output
isinf(x) : True2. Check if negative infinity is infinity
Assign x with negative infinity, and programmatically check if x is infinity value, using math.isinf().
Python Program
import math
x = -math.inf
result = math.isinf(x)
print('isinf(x) :', result)Output
isinf(x) : True3. Check if integer 8 is infinity
Assign x with a finite value, like 8, and programmatically check if x is infinity value, using math.isinf().
Python Program
import math
x = 8
result = math.isinf(x)
print('isinf(x) :', result)Output
isinf(x) : FalseSummary
In this Python Math tutorial, we learned the syntax of, and examples for math.isinf() function.