欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Python入门之三角函数tan()函数实例详解

程序员文章站 2022-07-18 16:22:29
描述 tan() 返回x弧度的正弦值。 语法 以下是 tan() 方法的语法: import math math.tan(x) 注意:t...

描述

tan() 返回x弧度的正弦值。

语法

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

import math
math.tan(x)

注意:tan()是不能直接访问的,需要导入 math 模块,然后通过 math 静态对象调用该方法。

参数

x -- 一个数值。

返回值

返回x弧度的正弦值,数值在 -1 到 1 之间。

实例

以下展示了使用 tan() 方法的实例:

#!/usr/bin/python
import math

print "tan(3) : ", math.tan(3)
print "tan(-3) : ", math.tan(-3)
print "tan(0) : ", math.tan(0)
print "tan(math.pi) : ", math.tan(math.pi)
print "tan(math.pi/2) : ", math.tan(math.pi/2)
print "tan(math.pi/4) : ", math.tan(math.pi/4)

以上实例运行后输出结果为:

tan(3) : -0.142546543074
tan(-3) : 0.142546543074
tan(0) : 0.0
tan(math.pi) : -1.22460635382e-16
tan(math.pi/2) : 1.63317787284e+16
tan(math.pi/4) : 1.0

总结

以上就是本文关于Python入门之三角函数tan()函数实例详解的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站:Python入门之三角函数sin()函数实例详解Python入门之三角函数atan2()函数详解简单了解Python中的几种函数等,有什么问题可以随时留言,小编会及时回复大家的。感谢朋友们对本站的支持!