现在位置: 首页 > Python 3 教程 > 正文

Python math.cos() 方法

Python math 模块 Python math 模块

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

Python 版本: 1.4

语法

math.cos() 方法语法如下:

math.cos(x)

参数说明:

  • x -- 必需,数字。如果 x 不是数字,则返回 TypeError。

返回值

返回一个浮点数,表示 x 的余弦值,介于 -1 到 1 之间。

实例

以下实例返回数字的余弦值:

实例

# 导入 math 包
import math

# 输出余弦值
print (math.cos(0.00))
print (math.cos(-1.23))
print (math.cos(10))
print (math.cos(3.14159265359))

输出结果:

1.0
0.3342377271245026
-0.8390715290764524
-1.0

Python math 模块 Python math 模块