Python cos() 関数

Python 数字Python 数値


説明

cos()x のラジアンの余弦値を返します。


構文

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

import math

math.cos(x)

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


引数

  • x -- 数値。

戻り値

x のラジアンの余弦値を返します。-1 から 1 の間です。


例

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

#!/usr/bin/python
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.9899924966
cos(-3) :  -0.9899924966
cos(0) :  1.0
cos(math.pi) :  -1.0
cos(2*math.pi) :  1.0

Python 数字Python 数値

その他の拡張