Python math.cos() 方法

定义和用法

math.cos() 方法返回数的余弦值。

实例

求不同数字的余弦值:

# 导入 math 库
import math 

# 返回不同数字的余弦值:
print (math.cos(0.00))
print (math.cos(-1.23))
print (math.cos(10))
print (math.cos(3.14159265359))

亲自试一试

语法

math.cos(x)

参数

参数 描述
x

必需。要计算其余弦值的数字。

如果该值不是数字,它将返回 TypeError。

技术细节

返回值: 从 -1 到 1 的浮点数值,代表角度的余弦值。
Python 版本: 1.4