Python math.isinf()-Methode
Python math.isinf()Die Methode bestimmt, ob x unendlich ist. Sie gibt True zurück, wenn x positiv oder negativ unendlich ist, andernfalls gibt sie False zurück.
Python-Version: 2.6
Syntax
Die Syntax der Methode math.isinf() lautet wie folgt:
math.isinf(x)
Parameterbeschreibung:
- x-- Erforderlich, eine Zahl. Gibt TypeError zurück, wenn x keine Zahl ist.
Rückgabewert
Gibt einen booleschen Wert zurück. Gibt True zurück, wenn x positiv oder negativ unendlich ist, andernfalls False.
Beispiel
Das folgende Beispiel prüft, ob eine Zahl unendlich ist:
Beispiel
# Importiere das math-Paket
import math
# Prüfen, ob die Zahl unendlich ist
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
# Prüfen, ob die Zahl unendlich ist
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))
Ausgabeergebnis:
False False False True False True True TrueAndere Erweiterungen
Python math-Modul