How to calculate trigonometric function cos () in Python
This article describes how to use the cos () method to calculate trigonometric functions in Python. It is the basic knowledge for getting started with Python. For more information, see
The cos () method returns the cosine of x radians.
Syntax
The syntax of the cos () method is as follows:
Cos (x)
Note: This function cannot be directly accessed. Therefore, we need to import the math module and then use the static object of math to call this function.
Parameters
X -- this must be a value
Return Value
This method returns a value ranging from-1 to 1, representing the cosine of the angle.
Example
The following example shows how to use the cos () method.
?
1
2
3
4
5
6
7
8 #! /Usr/bin/python
Import math
Print "cos (3):", math. cos (3)
Print "cos (-3):", math. cos (-3)
Print "cos (0):", math. cos (0)
Print "cos (math. pi):", math. cos (math. pi)
Print "cos (2 * math. pi):", math. cos (2 * math. pi)
When we run the above program, it will produce the following results:
?
1
2
3
4
5cos (3):-0.9899924966.
Cos (-3):-1, 0.9899924966
Cos (0): 1.0
Cos (math. pi):-1.0.
Cos (2 * math. pi): 1.0