Python數字cos()方法

Python數字cos()方法返回x弧度的余弦值。

語法

以下是cos()方法的語法 -

cos(x)

注意 - 此函數不能直接訪問,需要導入math模組,需要使用math靜態對象調用此函數。

參數

  • x - 此參數必須是數字值。

返回值

  • 此方法返回-11之間的數值,表示角度的余弦值。

示例

以下示例顯示了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.9899924966
cos(-3) :  -0.9899924966
cos(0) :  1.0
cos(math.pi) :  -1.0
cos(2*math.pi) :  1.0

上一篇: Python數字 下一篇: Python字串