What is math.acos() in Python?

The acos() functionalso called the arc cosine function in Python returns the inverse cosine of a number. To be more specific, it returns the inverse cosine of a number in the radians.

Figure 1 shows the mathematical representation of the acos() function, and Figure 2 shows the visual representation of the acos() function.

Figure 1: Mathematical representation of inverse cosine function
Figure 2: Visual representation of inverse cosine function

Note: The math module is required for this function.

To convert radians to degrees, use the following formula:

degrees = radians * ( 180.0 / pi )

Syntax

acos(num)

Parameter

This function requires a number as a parameter. The parameter must be a double value between -1 and 1.

  • -1 <= parameter <= 1

Return value

acos() returns the inverse cosine of a number (radians) that is sent as a parameter. The return value lies in interval [0, pi] radians.

Example

import math
#positive number in radians
print "The value of acos(0.5) : ", math.acos(0.5), "Radians"
#negative number in radians
print "The value of acos(-0.5) : ", math.acos(-0.5), "Radians"
#applying acos() and then converting the result in radians to degrees
#radians = 0.5
#PI = 3.14159265
result = math.acos(0.5) * (180.0 / math.pi)
print "The value of acos(0.5) : ", result ,"Degrees"