Python math.acos() – Arc / Inverse Cosine

Contents

Python math.acos()

math.acos() function returns the inverse cosine of given number.

The return value is angle in radians, and lies in [0, pi] radians.

Syntax

The syntax to call acos() function is

math.acos(x)

where

ParameterRequiredDescription
xYesA number in the range [-1, 1].

Note: If x is outside the allowed range, then acos(x) raises a ValueError.

Examples

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

Python Program

import math

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

Output

acos(x) : 1.0471975511965976 radians

We can convert the returned radians into degrees using math.degrees() function.

In the following example, we find the inverse cosine of 0.5 using acos() function and convert this returned radians to degrees.

Python Program

import math

x = 0.5
result = math.acos(x)
result = math.degrees(result)
print('acos(x) :', result, 'degrees')
Run Code Copy

Output

acos(x) : 59.99999999999999 degrees

Summary

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

Code copied to clipboard successfully 👍