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.
Learn Python on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours