Python cos() Function
Description
cos()Returns the cosine of x radians.
Syntax
The following is the syntax of the cos() method:
import math math.cos(x)
Note:cos() cannot be accessed directly; you need to import the math module, and then call the method via the math static object.
Parameters
- x -- A numeric value.
Return Value
Returns the cosine of x radians, between -1 and 1.
Example
The following example demonstrates the use of the 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)
The output of the above example after running is:
cos(3) : -0.9899924966 cos(-3) : -0.9899924966 cos(0) : 1.0 cos(math.pi) : -1.0 cos(2*math.pi) : 1.0Other Extensions
Python Numbers