Python中计算三角函数之cos()方法的使用简介

yipeiwu_com6年前Python基础

 cos()方法返回x弧度的余弦值。
语法

以下是cos()方法的语法:

cos(x)

注意:此函数是无法直接访问的,所以我们需要导入math模块,然后需要用math的静态对象来调用这个函数。
参数

  •     x -- 这必须是一个数值

返回值

此方法返回-1 到 1之间的数值,它表示角度的余弦值
例子

下面的例子展示cos()方法的使用

#!/usr/bin/python
import 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

相关文章

python Tkinter的图片刷新实例

调用python自带的GUI制作库 一开始想用Tkinter制作GUI的,网上说是python自带的,结果输入: import tkinter 后,显示: _ImportErr...

在Python中字符串、列表、元组、字典之间的相互转换

在Python中字符串、列表、元组、字典之间的相互转换

一、字符串(str) 字符串转换为列表 使用list()方法 str_1 = "1235" str_2 = 'zhangsan' str_3 = '''lisi''' tuple_1...

Python黑魔法@property装饰器的使用技巧解析

@property有什么用呢?表面看来,就是将一个方法用属性的方式来访问. 上代码,代码最清晰了. class Circle(object): def __init__...

Python制作CSDN免积分下载器

Python制作CSDN免积分下载器

CSDN免积分下载 你懂的。 1、输入资源地址如:http://download.csdn.net/download/gengqkun/4127808 2、输入验证码 3、点击下载,会...

python 多进程并行编程 ProcessPoolExecutor的实现

使用 ProcessPoolExecutor from concurrent.futures import ProcessPoolExecutor, as_completed im...