Método Python math.isinf()
Python math.isinf()El método determina si x es infinito, si x es infinito positivo o negativo, devuelve True, de lo contrario devuelve False.
Versión de Python: 2.6
Sintaxis
La sintaxis del método math.isinf() es la siguiente:
math.isinf(x)
Descripción de parámetros:
- x-- Obligatorio, número. Si x no es un número, devuelve TypeError.
Valor de retorno
Devuelve un valor booleano, si x es infinito positivo o negativo, devuelve True, de lo contrario devuelve False.
Ejemplo
El siguiente ejemplo comprueba si un número es infinito:
Ejemplo
# Importar el paquete math
import math
# Comprobar si el número es infinito
print(math.isinf(56))
print(math.isinf(-45.34))
print(math.isinf(+45.34))
print(math.isinf(math.inf))
print(math.isinf(float("nan")))
print(math.isinf(float("inf")))
print(math.isinf(float("-inf")))
print(math.isinf(-math.inf))
import math
# Comprobar si el número es infinito
print(math.isinf(56))
print(math.isinf(-45.34))
print(math.isinf(+45.34))
print(math.isinf(math.inf))
print(math.isinf(float("nan")))
print(math.isinf(float("inf")))
print(math.isinf(float("-inf")))
print(math.isinf(-math.inf))
Salida:
False False False True False True True TrueOtras extensiones
Módulo Python math