Metoda Python math.isfinite().
Příklad
Zkontrolujte, zda je hodnota konečná nebo ne:
# Import math Library
import math
# Check whether the values are
finite or not
print(math.isfinite(2000))
print(math.isfinite(-45.34))
print(math.isfinite(+45.34))
print(math.isfinite(math.inf))
print(math.isfinite(float("nan")))
print(math.isfinite(float("inf")))
print(math.isfinite(float("-inf")))
print(math.isfinite(-math.inf))
print(math.isfinite(0.0))
Definice a použití
Metoda math.isfinite()
kontroluje, zda je číslo konečné nebo ne.
Tato metoda vrací True, pokud je zadané číslo konečné číslo, jinak vrací False.
Syntax
math.isfinite(x)
Hodnoty parametrů
Parameter | Description |
---|---|
x | Required. The value to check. Must be a number (float/integer/infinite/NaN/finite) |
Technické údaje
Návratová hodnota: | Hodnota bool , True, pokud je x konečné, False, pokud x je buď nekonečno nebo NaN |
---|---|
Verze Pythonu: | Novinka v Pythonu 3.2 |