• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / Python / math.degrees() Python – How to Convert Radians to Degrees in Python

math.degrees() Python – How to Convert Radians to Degrees in Python

February 4, 2022 Leave a Comment

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.

Other Articles You'll Also Like:

  • 1.  Find Maximum of Three Numbers in Python
  • 2.  pandas covariance – Calculate Covariance Matrix Using cov() Function
  • 3.  How to Check if a Dictionary is Empty in Python
  • 4.  Are Dictionaries Mutable in Python? Yes, Dictionaries are Mutable
  • 5.  Using Python to Add Trailing Zeros to String
  • 6.  pandas Duplicated – Find Duplicate Rows in DataFrame or Series
  • 7.  Get Last Character in String in Python
  • 8.  Python Add Days to Date Using datetime timedelta() Function
  • 9.  Write Inline If and Inline If Else Statements in Python
  • 10.  How to Find the Longest String in List in Python

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy