 # How to Convert Degrees to Radians in Python and vice versa

Radians are mostly used when you want to do mathematical calculations on a Circular object or path. Python has inbuilt functions that can convert radians to degrees and degrees to radians. In this entire tutorial, you will know how to convert radians to degrees and vice-versa in python using various examples.

## How to Convert Degrees to radians in Python

In this section, you will know to convert radians to degrees in python. Suppose I want to use degree inside the NumPy cos() method.  As this function accepts only radian values so I have to convert it to radians. There is a python module that allows this conversion and it is math.radians().

``````import math
import numpy as np

The above code first converted the degrees to radians and then the results are passed as an argument to the numpy.cos() method. You will get the following output when you will run the code.

Output

The other method to convert degrees to radians is to define your own custom function. Inside the function, you will use the radians conversion formulae. The following are the lines of code for the function.

``````import math
import numpy as np

return degree * math.pi/180

You can see in the function I am taking degree as a parameter and converting it to radians using formulae degree * pi/180.

You will get the same output as the first method.

Output

Python module also provides a method to convert radians to degrees. And that function is math.degrees(). Inside this method, you will put radian value and it will convert radian to degrees.  Let’s take the output of the radian of the above methods (30) and convert it back to degrees.

Execute the below lines of code.

``````import math
import numpy as np
print(degrees)``````

In the above code, you can see I am taking radian input and passing it to the degrees() method. It will convert back the radian to degrees. You will get the following output.

These are examples of how to convert degree to radians in python and vice-versa. I hope you have liked this tutorial. If you have any queries then you can contact us for more help. 