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

ParameterRequiredDescription
xYesA numeric value.

Examples

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

Output

isinf(x) : True

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

Output

isinf(x) : True

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)
Run

Output

isinf(x) : False

Summary

In this Python Examples tutorial, we learned the syntax of, and examples for math.isinf() function.