Python3 tan() Function
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
- x -- a numeric value representing an angle.
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
(
"
(tan(3) :
"
,
math
.
tan
(
3
)
)
(
"
tan(-3) :
"
,
math
.
tan
(
3
)
)
(
"
tan(0) :
"
,
math
.
tan
(
0
)
)
(
"
tan(math.pi) :
"
,
math
.
tan
(
math
.
pi
)
)
(
"
tan(math.pi/2) :
"
,
math
.
tan
(
math
.
pi
/
2
)
)
(
"
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