To convert radians to degrees for use in trigonometric functions in Python, the easiest way is with the math.degrees() function from the Python math module.

import math

degrees = math.degrees(math.pi/2)

The Python math module has many powerful functions which make performing certain calculations in Python very easy.

One such calculation which is very easy to perform in Python is converting radians to degrees.

We can convert radians to degrees easily with the Python math module degrees() function.

To do so, we need to pass any number to the Python math degrees() function.

Below are a few examples of how to use the degrees() function to convert different angles, in radians, to degrees with in Python.

import math

print(math.degrees(0))
print(math.degrees(math.pi/6))
print(math.degrees(math.pi/3))
print(math.degrees(math.pi/2))

#Output:
0.0
29.999999999999996
59.99999999999999
90.0

If you’d like to go the other way, converting degrees to radians, you can use the math.radians() Python function.

Converting Radians to Degrees Without the math Module in Python

Converting radians to degrees is a very easy formula. To convert radians to degrees, all we need to do is multiply the degrees by 180 and divide by pi.

We can convert radians to degrees without the help of the math module easily in Python.

Below is a user-defined function which will convert radians to degrees for us in our Python code.

def radians_to_degrees(degrees):
  return radians * (180/math.pi)

Let’s test the function to verify that we get the same results as the math.degrees() Python function.

def radians_to_degrees(radians):
  return radians * (180/math.pi)

print(radians_to_degrees(0))
print(radians_to_degrees(math.pi/6))
print(radians_to_degrees(math.pi/3))
print(radians_to_degrees(math.pi/2))

#Output:
0.0
29.999999999999996
59.99999999999999
90.0

As you can compare for yourself to the example above, we get the same results as using math.degrees()

Hopefully this post was helpful for you to learn how to convert radians to degrees in Python with and without the math.degrees() Python function.

Categorized in:

Python,

Last Update: February 26, 2024