Python math.isinf() Method

Python math 模块Python math Module

Python math.isinf()The method determines whether x is infinity. Returns True if x is positive or negative infinity, otherwise returns False.

Python Version: 2.6

Syntax

The syntax of the math.isinf() method is as follows:

math.isinf(x)

Parameter Description:

  • x-- Required, a number. Returns TypeError if x is not a number.

Return Value

Returns a boolean value. Returns True if x is positive or negative infinity, otherwise returns False.

Example

The following example checks whether a number is infinity:

Example

# Import the math package
import math

# Check whether the number is infinity
print(math.isinf(56))
print(math.isinf(-45.34))
print(math.isinf(+45.34))
print(math.isinf(math.inf))
print(math.isinf(float("nan")))
print(math.isinf(float("inf")))
print(math.isinf(float("-inf")))
print(math.isinf(-math.inf))

Output result:

False
False
False
True
False
True
True
True

Python math 模块Python math Module

Other Extensions