math.isinf()
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 mathprint(math.isinf(float('inf'))) # Positive infinityprint(math.isinf(float('-inf'))) # Negative infinityprint(math.isinf(1000)) # Finite number
This code outputs:
TrueTrueFalse
Codebyte Example
Run the following codebyte to understand how the math.isinf()
works in various scenarios:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.