Python math.degrees() function


The math.degrees() function in Python is used to convert an angle from radians to degrees. This is useful in various mathematical calculations, especially in trigonometry, where angles are often measured in degrees.

Syntax

import math result = math.degrees(x)
  • x: The angle in radians that you want to convert to degrees.

Return Value

  • Returns the angle in degrees as a float.

Examples

  1. Converting radians to degrees:

    import math result = math.degrees(math.pi) # Convert π radians to degrees print(result) # Output: 180.0
  2. Converting a smaller angle:

    result = math.degrees(math.pi / 4) # Convert π/4 radians to degrees print(result) # Output: 45.0
  3. Converting a negative angle:

    result = math.degrees(-math.pi / 2) # Convert -Ï€/2 radians to degrees print(result) # Output: -90.0
  4. Using math.degrees() in expressions: You can combine math.degrees() with other calculations:

    angle_rad = 1.0 # 1 radian result = math.degrees(angle_rad) + 10 print(result) # Output: 57.29577951308232 (approximately)

Summary

  • The math.degrees() function converts an angle from radians to degrees.
  • The output is always a float.
  • This function is especially useful in trigonometric calculations and when dealing with angles in degrees, which are more commonly used in many applications, such as navigation, engineering, and graphics.