Linux 拨号vps windows公众号手机端

python怎么导入cos函数

lewis 6年前 (2019-03-23) 阅读数 13 #程序编程
文章标签 python

在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

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门