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