math.isinf()

chmst_promotheus's avatar
Published Sep 4, 2024
Contribute to Docs

The math.isinf() function in Python checks whether a given value is infinite. It returns True if the value is positive or negative infinity, and False otherwise. This function is part of the math module and is useful when dealing with calculations that may result in infinite values.

Syntax

math.isinf(x)
  • x: The number to be checked for infinity.

Example

The following example demonstrates how to use the math.isinf() function:

import math
print(math.isinf(float('inf'))) # Positive infinity
print(math.isinf(float('-inf'))) # Negative infinity
print(math.isinf(1000)) # Finite number

This code outputs:

True
True
False

Codebyte Example

Run the following codebyte to understand how the math.isinf() works in various scenarios:

Code
Output
Loading...

All contributors

Contribute to Docs

Learn Python on Codecademy