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

yipeiwu_com6年前Python基础

描述

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中的几种函数等,有什么问题可以随时留言,小编会及时回复大家的。感谢朋友们对本站的支持!

相关文章

Python函数式编程指南(二):从函数开始

2. 从函数开始 2.1. 定义一个函数 如下定义了一个求和函数: 复制代码 代码如下: def add(x, y):     return x + y...

SublimeText 2编译python出错的解决方法(The system cannot find the file specified)

[Error 2] The system cannot find the file specified 解决方法:1.环境变量path添加:C:\Python32\Tools\Scrip...

从django的中间件直接返回请求的方法

实例如下所示: #coding=utf-8 import json import gevent from django.http import HttpResponse from s...

简单谈谈python的反射机制

  对编程语言比较熟悉的朋友,应该知道“反射”这个机制。Python作为一门动态语言,当然不会缺少这一重要功能。然而,在网络上却很少见到有详细或者深刻的剖析论文。下面结合一个web路由的...

Python获取当前函数名称方法实例分享

本文实例主要是Python中获取当前运行函数的名称,具体如下。 python 具有强大的自省能力,在函数运行时,可以在函数内部获取到当前所在的函数名称,请看示例代码 #coding=...