⊕
⊖
Contents
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)
Run Code CopyOutput
isinf(x) : True
2. 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)
Run Code CopyOutput
isinf(x) : True
3. 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().
Output
isinf(x) : False
Summary
In this Python Math tutorial, we learned the syntax of, and examples for math.isinf() function.