Python3 cos() Function

Python3 数字Python3 Numbers


Description

cos()Returns the cosine of x radians.


Syntax

The syntax for 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 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 shows the usage of the cos() method:

#!/usr/bin/python3
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 execution is:

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

Python3 数字Python3 Numbers

Other Extensions