温馨提示×

python怎么导入cos函数

九三
310
2021-02-14 11:18:49
栏目: 编程语言

python怎么导入cos函数

在python中导入cos函数的方法

在python中使用cos函数时,cos()函数无法直接访问,需要先导入math模块,在通过静态对象调用;

cos():cos函数的作用是返回x的弧度的余弦值。

cos()函数语法:

import math

math.cos(x)

cos()函数使用方法:

import math #导入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)

输出结果为:

cos(3) : -0.9899924966

cos(-3) : -0.9899924966

cos(0) : 1.0

cos(math.pi) : -1.0

cos(2*math.pi) : 1.0

0