Python math.cos() Method

Python math 模块Python math Module

Python math.cos(x)Returns the cosine of x radians.

Python Version: 1.4

Syntax

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

math.cos(x)

Parameter Description:

  • x-- Required, a number. If x is not a number, it returns a TypeError.

Return Value

Returns a floating-point number representing the cosine of x, between -1 and 1.

Example

The following example returns the cosine of a number:

Example

# Import the math package
import math

# Output the cosine value
print (math.cos(0.00))
print (math.cos(-1.23))
print (math.cos(10))
print (math.cos(3.14159265359))

Output result:

1.0
0.3342377271245026
-0.8390715290764524
-1.0

Python math 模块Python math Module

Other Extensions