Python math.log2() メソッド
Python math.log2(x)このメソッドは x の 2 を底とする対数を返します。
構文
math.log2() メソッドの構文は次のとおりです:
math.log2(x)
パラメータの説明:
- x-- 必須、数値。x が数値でない場合、TypeError を返します。値が 0 または負の場合は、ValueError を返します。
戻り値
数値の 2 を底とする自然対数を表す浮動小数点数 float を返します。
例
次の例は、数値の 2 を底とする自然対数を返します:
例
# math モジュールをインポート
import math
# 数値の 2 を底とする自然対数を出力
print(math.log2(2.7183))
print(math.log2(2))
print(math.log2(1))
import math
# 数値の 2 を底とする自然対数を出力
print(math.log2(2.7183))
print(math.log2(2))
print(math.log2(1))
出力結果:
1.4427046851812222 1.0 0.0その他の拡張
Python math モジュール