Python cos () function
description
cos () Returns the cosine of x radians.
grammar
The following is the syntax cos () method:
import math math.cos(x)
Note: cos () is not directly accessible, you need to import math module, and then call the method by math static objects.
parameter
- x - a value.
return value
Returns the cosine of x radians, between -1 to 1.
Examples
The following shows an example of the use of cos () method:
#!/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)
After running the above example output is:
cos(3) : -0.9899924966 cos(-3) : -0.9899924966 cos(0) : 1.0 cos(math.pi) : -1.0 cos(2*math.pi) : 1.0