Python math.cos() – Cosine Function

Contents

Python math.cos()

math.cos(x) function returns the cosine of x radians.

The return value lies in [-1, 1].

Syntax

The syntax to call cos() function is

math.cos(x)

where

ParameterRequiredDescription
xYesA numeric value that represents angle in radians.

Examples

In the following example, we find the cosine of 0.5 radians using cos() function of math module.

Python Program

import math

x = 0.5 #radians
result = math.cos(x)
print('cos(x) :', result)
Run Code Copy

Output

cos(x) : 0.8775825618903728

We can take angle in degrees and convert the degrees into radians using math.radians() function, and then find the cosine of this angle.

In the following program, we find the cosine of 60 degrees.

Python Program

import math

x = 60 #degrees
x = math.radians(x) #radians
result = math.cos(x)
print('cos(x) :', result)
Run Code Copy

Output

cos(x) : 0.5000000000000001

Summary

In this Python Examples tutorial, we learned the syntax of, and examples for math.cos() function.

Related Tutorials

Code copied to clipboard successfully 👍