How to use Trigonometric functions in Python math module

The Python math module has a number of useful trigonometric functions. Lets discuss some code snippets and understand how to use trigonometric functions in Python math module.

Calculating sine of an angle

The sine of an acute angle of a right angle triangle is defined as the ratio of the length of the side that is opposite to the specified angle to the length of the longest side of the triangle. (Read more about sine and cosine)

The sin(x) function in Python math module is used to calculate the sine of an angle. The angle has to be specified in radians.

import math
x=1.571     #angle in radians
y = math.sin(x)
print("The sine of", x, "is", y)

Calculating cosine of an angle

The cosine of an acute angle of a right angle triangle is defined as the ratio of the adjacent length of the specified angle to the length of the longest side of the triangle. (Read more about sine and cosine)

The cos(x) function in Python math module is used to calculate the cosine of an angle. The angle has to be specified in radians.

import math
x=1.571     #angle in radians
y = math.cos(x)
print("The cosine of", x, "is", y)

Calculating tangent of an angle

The tangent of an acute angle of a right angle triangle is defined as the ratio of the length of the side that is opposite to the specified angle to the adjacent length of the specified angle. (Read more about trigonometric functions)

The tan(x) function in Python math module is used to calculate the tangent of an angle. The angle has to be specified in radians.

import math
x=1.571     #angle in radians
y = math.tan(x)
print("The tangent of", x, "is", y)