Python math.isinf() Method

Python math.isinf() Method

  1. Syntax
  2. Parameters
  3. Returns
  4. Example Code: Use of the math.isinf() Method

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 Waseem avatar Musfirah Waseem avatar

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.

LinkedIn

Related Article - Python Math

  • Python math.pow() Method
  • Python Math.erf() Method
  • Python Math.erfc() Method
  • Python Math.expm1() Method
  • Python Math.fabs() Method
  • Python Math.factorial() Method