math.isfinite()
Anonymous contributor
Anonymous contributor2 total contributions
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 contributorAnonymous contributor2 total contributions
- Anonymous contributor
Looking to contribute?
- 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.