这篇文章主要介绍了Python中计算三角函数之cos()方法的使用简介,是Python入门的基础知识,需要的朋友可以参考下
cos()方法返回x弧度的余弦值.
语法
以下是cos()方法的语法:
cos(x)
注意:此函数是无法直接访问的,所以我们需要导入math模块,然后需要用math的静态对象来调用这个函数.
参数
x
--
这必须是一个数值
返回值
此方法返回-1
到
①.之间的数值,它表示角度的余弦值
例子
下面的例子展示cos()方法的使用
import
math
:
",
"cos(0)
math.cos(0)
"cos(math.pi)
math.cos(math.pi)
当我们运行上面的程序,它会产生以下结果:
cos(0)
①0
cos(math.pi)
-1.0
描述
sin()返回的x弧度的正弦值.
以下是sin()方法的语法:
importmath
math.sin(x)
注意:sin()是不能直接访问的,需要导入math模块,然后通过math静态对象调用该方法.
x--一个数值.
返回的x弧度的正弦值,数值在-1到1之间.
实例
以下展示了使用sin()方法的实例:
#!/usr/bin/python
import math
print "sin(0) : ", math.sin(0)
print "sin(math.pi) : ", math.sin(math.pi)
以上实例运行后输出结果为:
sin(0) : 0.0
总结