Python3 tan() Function

Python3 数字Python3 Numbers


Description

tan()The function ismatha function in the module, used to calculate the tangent of an angle.

To use the tan() function, you first need to import the math module, then callmath.tan()the function, passing an angle (in radians) as a parameter.

Syntax

The following is the syntax of the tan() method:

import math

math.tan(x)

Note:tan() cannot be accessed directly; you need to import the math module, and then call the method via the math static object.


Parameters

  • x -- A numeric value, an angle.

Return Value

Returns the tangent of x radians, with the result ranging between -math.pi/2 and math.pi/2.


Example

The following shows an example of using the tan() method:

Example (Python 3.0+)

#!/usr/bin/python3 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))

The output after running the above example is:

(tan(3) :  -0.1425465430742778
tan(-3) :  0.1425465430742778
tan(0) :  0.0
tan(math.pi) :  -1.2246467991473532e-16
tan(math.pi/2) :  1.633123935319537e+16
tan(math.pi/4) :  0.9999999999999999

Python3 数字Python3 Numbers

Other Extensions