# Python math.isinf() Method

Musfirah Waseem Jan 30, 2023 Sep 22, 2022

Python `math.isinf()` method is an efficient way of finding whether a number is infinite or not. It returns `True` if the number is infinite (it can be positive or negative infinity); otherwise, `False`.

## Syntax

``````math.isinf(x)
``````

## Parameters

`x` The number to check can be positive or negative.

## Returns

The return type for this method is a Boolean value. `True` is returned if `x` is an infinite value; otherwise, `False`.

## Example Code: Use of the `math.isinf()` Method

Example Code:

``````import math

x = 100
value= math.isinf(x)
print(f"Is {x} an infinite number? {value}")

x = 0
value= math.isinf(x)
print(f"Is {x} an infinite number? {value}")

x = math.inf
value= math.isinf(x)
print(f"Is {x} an infinite number? {value}")

x = -math.inf
value= math.isinf(x)
print(f"Is {x} an infinite number? {value}")

value= math.isinf((float("nan")))
print(f"Is NaN an infinite number? {value}")
``````

Output:

``````Is 100 an infinite number? False
Is 0 an infinite number? False
Is inf an infinite number? True
Is -inf an infinite number? True
Is NaN an infinite number? False
``````

Note that the above code shows how we can use this method.

Musfirah is a student of computer science from the best university in Pakistan. She has a knack for programming and everything related. She is a tech geek who loves to help people as much as possible.