What is math.isfinite() in Python?
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
mathmodule is required to use this function.
Syntax
math.isfinite(number)
Parameter
This function requires the number as a parameter.
Return value
This function returns True if the value is finite; otherwise, it returns False.
Example
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")))