Python 3 教程
cos() 返回x的弧度的余弦值。
以下是 cos() 方法的語(yǔ)法:
import math math.cos(x)
注意:cos()是不能直接訪問(wèn)的,需要導(dǎo)入 math 模塊,然后通過(guò) math 靜態(tài)對(duì)象調(diào)用該方法。
返回x的弧度的余弦值,-1 到 1 之間。
以下展示了使用 cos() 方法的實(shí)例:
#!/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))
以上實(shí)例運(yùn)行后輸出結(jié)果為:
cos(3) : -0.9899924966004454 cos(-3) : -0.9899924966004454 cos(0) : 1.0 cos(math.pi) : -1.0 cos(2*math.pi) : 1.0其他擴(kuò)展