python怎么导入cos函数

994
2021/2/14 11:18:49
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

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

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: python中len函数的用途有哪些