Python3 cos() 関数

Python3 数字Python3 数値


説明

cos()xのラジアンのコサイン値を返します。


構文

以下は cos() メソッドの構文です:

import math

math.cos(x)

注意:cos() は直接アクセスできません。math モジュールをインポートし、math 静的オブジェクトを介してこのメソッドを呼び出す必要があります。


パラメータ

  • x -- 数値。

戻り値

xのラジアンのコサイン値を返します。-1 から 1 の間です。


例

以下は cos() メソッドを使用した例です:

#!/usr/bin/python3
import math

print ("cos(3) : ",  math.cos(3))
print ("cos(-3) : ",  math.cos(-3))
print ("cos(0) : ",  math.cos(0))
print ("cos(math.pi) : ",  math.cos(math.pi))
print ("cos(2*math.pi) : ",  math.cos(2*math.pi))

上記の例を実行した後の出力結果は次のとおりです:

cos(3) :  -0.9899924966004454
cos(-3) :  -0.9899924966004454
cos(0) :  1.0
cos(math.pi) :  -1.0
cos(2*math.pi) :  1.0

Python3 数字Python3 数値

その他の拡張