Python math.isinf() Method

The math.isinf() method is used to check whether a number is infinite(either positive or negative infinity).

Syntax

import math
math.isinf(num)

Parameter

num(required): The value to be checked. Here num can be an integer, float, double, finite inf, NaN, etc.

Return Value

It returns True if the given number is an infinite, otherwise False.

Visual Representation

Visual Representation of Python math.isinf()

Example 1: How to Use math.isinf() method

import math

print(math.isinf(14)) #integer number
print(math.isinf(10.05)) #float number
print(math.isinf(-14)) #negative number
print(math.isinf(-10.05))

Output

False
False
False
False

Example 2: Passing Infinity Values and NaN

Visual Representation of Passing Infinity Values and NaN

import math

print(math.isinf(float("inf")))
print(math.isinf(float("-inf")))
print(math.isinf(float("nan")))

Output

True
True
False

That’s it.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.