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