Python math.isinf() メソッド

Python math 模块Python math モジュール

Python math.isinf()メソッドは、x が無限大かどうかを判定します。x が正または負の無限大の場合は True を返し、それ以外の場合は False を返します。

Python バージョン:2.6

構文

math.isinf() メソッドの構文は次のとおりです:

math.isinf(x)

パラメータの説明:

  • x-- 必須、数値。x が数値でない場合、TypeError を返します。

戻り値

ブール値を返します。x が正または負の無限大の場合は True を返し、それ以外の場合は False を返します。

例

次の例では、数値が無限大かどうかをチェックします:

例

# math モジュールをインポート
import math

# 数値が無限大かどうかをチェック
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))

出力結果:

False
False
False
True
False
True
True
True

Python math 模块Python math モジュール

その他の拡張