Python3 cos() 函數(shù)

Python3 數(shù)字 Python3 數(shù)字


描述

cos() 返回x的弧度的余弦值。


語(yǔ)法

以下是 cos() 方法的語(yǔ)法:

import math

math.cos(x)

注意:cos()是不能直接訪問(wèn)的,需要導(dǎo)入 math 模塊,然后通過(guò) math 靜態(tài)對(duì)象調(diào)用該方法。


參數(shù)

  • x -- 一個(gè)數(shù)值。

返回值

返回x的弧度的余弦值,-1 到 1 之間。


實(shí)例

以下展示了使用 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

Python3 數(shù)字 Python3 數(shù)字