Python math.degrees() Method

In this tutorial, we will go through the details of using this method including the function syntax, parameters, return values, and practical examples on how to use it.

Python math.degrees() Method

The math.degrees() function in Python is a built-in function that is part of the math module. It allows us to converts an angle from radians to degrees.

The Python Math Module

The math module in Python provides a set of mathematical functions, constants, and implementations that allow us to perform mathematical tasks that go beyond the basic arithmetic provided by Python.

To use the math module, need to import it using the import keyword.

import math

Once import, we can access all the functions and constants provided by the math module.

Python Degrees Function Syntax

The syntax for the math.degrees() function is as shown below:


Where the parameter x refers to the angle in radians that you wish to convert into degrees.

Function Return Value

The function will return a floating-point number where denotes the degrees.

Using the math.degrees() Function

Let us explore some basic examples on how we can use this function in Python.

Example 1 - Converting Radians to Degrees

Suppose we have an angle of 1 radian, and we wish to convert it into degrees, we can use the degrees() function as shown:

import math

radians = 1
degrees = math.degrees(radians)




Example 2 - Converting π Radians to Degrees

In math, the value of π radians is equivalent to 180 degrees. We can confirm this by using the degrees function as demonstrated below:

import math

radians = math.pi
degrees = math.degrees(radians)




Example 3 - Converting Negative Radians to Degrees

We can also use the math.degrees() function with negative radians. An example is as shown below:

import math

radians = -1
degrees = math.degrees(radians)




NOTE: The input to math.degrees() must be a number (integer or float). If you pass an argument of a different type, you will get a TypeError.

import math

radians = ''
degrees = math.degrees(radians)


In this case, the function will raise a TypeError as the input is a str.

TypeError                                 Traceback (most recent call last)
      1 import math
      3 radians = ''
----> 4 degrees = math.degrees(radians)
      6 print(degrees)

TypeError: must be real number, not str


That's a comprehensive guide to the math.degrees() method in Python. This function is an essential tool when working with angles, especially in fields such as physics, engineering, and computer graphics, where you often need to convert between degrees and radians. Happy coding!

Table of Contents
Great! Next, complete checkout for full access to GeekBits.
Welcome back! You've successfully signed in.
You've successfully subscribed to GeekBits.
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info has been updated.
Your billing was not updated.