Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python3 tan() Function

Python3 tan() Function

Python3 Numbers Python3 Numbers


Description

The tan() function is a function in the math module used to compute the tangent of an angle.

To use the tan() function, first import the math module, then call the math.tan() function, passing an angle (in radians) as the argument.

Syntax

The syntax of the tan() method is as follows:


import math

math.tan(x)

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


Parameters


Return Value

Returns the tangent of x radians, with the result in the range -math.pi/2 to math.pi/2.


Example

The following shows examples 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

)

)

Running the example above produces:


(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 Numbers Python3 Numbers