Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python cos() function

Python cos() function

Python Numbers Python Numbers


Description

cos() Returns the cosine of x radians.


Syntax

The syntax of the cos() method is as follows:



import math



math.cos(x)

**Note:** cos() cannot be accessed directly; you need to import the math module and call the method through the static math object.


Parameters


Return Value

Returns the cosine of x radians, between -1 and 1.


Example

The following shows examples of using 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)

Running the example above produces:



cos(3) :  -0.9899924966

cos(-3) :  -0.9899924966

cos(0) :  1.0

cos(math.pi) :  -1.0

cos(2*math.pi) :  1.0

Python Numbers Python Numbers