Python Number cos() Method



The cos() method in Python number returns the cosine of x radians. In Python, the math module comprises a number of mathematical operations that can be performed easily and the cos() function is one of them. It returns the cosine of the value that has been passed as an argument. The value that is passed in this function must be in radians.


Here is the syntax for cos() method:


Note − One cannot access this function directly, so it is required to import the math module in Python and then we are supposed to call this function making use of the math static object.


  • x − This should be a numeric value.

Return Value

This method in the Python math module returns a numeric value that lies between -1 and 1, that represents the cosine of the angle.


The example below shows the usage of cos() method.

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 above program, it produces following result:

cos(3) :  -0.9899924966
cos(-3) :  -0.9899924966
cos(0) :  1.0
cos(math.pi) :  -1.0
cos(2*math.pi) :  1.0

Here at Intellinuts, we have created a complete Python tutorial for Beginners to get started in Python.