Home »
Python
math.degrees() method with example in Python
Python math.degrees() method: Here, we are going to learn about the math.degrees() method with example in Python.
Submitted by IncludeHelp, on April 25, 2019
Python math.degrees() method
math.degrees() method is a library method of math module, it is used to convert angle value from radians to degree, it accepts a number and returns the angle value in degree.
Note: math.degrees() method accepts only numbers, if we provide anything else except the number, it returns error TypeError – "TypeError: a float is required".
Syntax of math.degrees() method:
math.degrees(x)
Parameter(s): x – is the number in radians to be converted into degree.
Return value: float – it returns a float value that is the angle value in degree.
Example:
Input:
x = 10.25
# function call
print(math.degrees(x))
Output:
587.2817400090938
Python code to demonstrate example of math.degrees() method
# Python code to demonstrate example of
# math.degrees() method
# importing math module
import math
# number in radians
x = 0
print("math.degrees(",x,"): ", math.degrees(x))
x = 0.25
print("math.degrees(",x,"): ", math.degrees(x))
x = 10.25
print("math.degrees(",x,"): ", math.degrees(x))
x = -0.25
print("math.degrees(",x,"): ", math.degrees(x))
Output
math.degrees( 0 ): 0.0
math.degrees( 0.25 ): 14.32394487827058
math.degrees( 10.25 ): 587.2817400090938
math.degrees( -0.25 ): -14.32394487827058
TypeError example
# Python code to demonstrate example of
# math.degrees() method with exception
# importing math module
import math
# number in radians
x = "10"
print("math.degrees(",x,"): ", math.degrees(x))
Output
Traceback (most recent call last):
File "/home/main.py", line 9, in <module>
print("math.degrees(",x,"): ", math.degrees(x))
TypeError: a float is required