平方根の値を取得するPythonコード
平方根の値をPythonで計算してみよう。
平方根の値の取得
math
モジュールのsqrt(x)
で平方根 $\sqrt{x}$ の値を取得することができる。
numpy
モジュールのsqrt(x)
でも平方根 $\sqrt{x}$ の値を取得することができる。
Python. $\sqrt{2}$ の値を取得して表示する。
import math
import numpy as np
print(math.sqrt(2))
print(np.sqrt(2))
$1.4142135623730951$
$1.4142135623730951$
と表示された。