The math.isfinite()
function in Python returns True
if the value is finite
; otherwise, it returns False
. In other words, this function is used to check if the number is finite or not.
Figure 1 shows the visual representation of the math.isfinite()
function.
The
math
module is required to use this function.
math.isfinite(number)
This function requires the number as a parameter.
This function returns True
if the value is finite
; otherwise, it returns False
.
The following example shows how to use math.isfinite()
in Python.
import math#numberprint ("math.isfinite(4):", math.isfinite(4))print ("math.isfinite(3.5):", math.isfinite(3.5))print ("math.isfinite(-2.6):", math.isfinite(-2.6))print ("math.isfinite(0):", math.isfinite(0))#nanprint ("math.isfinite(nan):", math.isfinite(float("nan")))#infinityprint ("math.isfinite(inf):", math.isfinite(float("inf")))print ("math.isfinite(-inf):", math.isfinite(float("-inf")))