math.isfinite()
Anonymous contributor
Published Aug 28, 2024
Contribute to Docs
The math.isfinite()
function returns True
when a number is finite and False
otherwise. A finite number is neither infinite nor NaN
.
Syntax
math.isfinite(x)
x
: The number to be checked. It can be an integer, float, or any numerical value.
Example
The following example uses math.isfinite()
to check whether the specified values are finite or not:
import math# Check if 0.1 is a finite numberprint(math.isfinite(0.1))# Check if positive infinity is a finite numberprint(math.isfinite(math.inf))# Check if the float representation of infinity is a finite numberprint(math.isfinite(float("inf")))# Check if the float representation of NaN (Not a Number) is a finite numberprint(math.isfinite(float("NaN")))
The output generated is as follows:
TrueFalseFalseFalse
Codebyte Example
Run the following example that uses the math.isfinite()
function to understand it works:
All contributors
- Anonymous contributor
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