AppDividend
Latest Code Tutorials

Python degrees() Function | Math.degrees() in Python Example

0

Python degrees() is an inbuilt method that is defined under the math module, which is used to convert the angle x( which is the parameter ) from radians into degrees. For example, if x is passed as a parameter in degrees function (degrees(x)), it returns the degree value of an angle. We can use the math module by importing it. The syntax for it would be import math; after importing, we use to call this function using the static object.

Python degrees()

Python math.degrees() function exists in the Standard math Library of Python Programming Language. The purpose of this function is to convert the value of angle x from radians to degrees.

Syntax

math.degrees(var)

Here var is the variable which we have to convert from radians into degrees.

Parameters

It takes one parameter var, which takes values of numeric datatype and throws type error if an argument is of any other data type is passed.

Return Value

It returns the degree value of the number in the float datatype.

Example programs on degrees() method in Python

Example 1: Write a program to show the working of degrees() method in Python.

import math
a1 = 0.36
b1 = 1
c1 = -1
d1 = -0.36

print("Value for parameter ", a1, " is ", math.degrees(a1))
print("Value for parameter ", b1, " is ", math.degrees(b1))
print("Value for parameter ", c1, " is ", math.degrees(c1))
print("Value for parameter ", d1, " is ", math.degrees(d1))

Output

Value for parameter  0.36  is  20.626480624709636
Value for parameter  1  is  57.29577951308232
Value for parameter  -1  is  -57.29577951308232
Value for parameter  -0.36  is  -20.626480624709636

In this example, we have seen that by passing a valid parameter in the degrees function, we get the value of the angle in degrees. Here we have passed different angles and got different values.

Example 2: Write a program to pass a value out of range from the degrees() function and display the output.

See the following code example.

import math

a = 'I am a web developer!'
print(math.degrees(a))

Output

TypeError: must be real number, not str

In this example, we’ve seen that passing a parameter, which is not a real number, throws a TypeError.

Conclusion

Python math.degrees() is an inbuilt function that returns floating-point number (a conversion of angle x from radians to degrees).

See also

Python tan()

Python sin()

Python hypot()

Python atan()

Python atan2()

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.