Python 3 – Number degrees() Method
The degrees() method is a built-in function in Python 3 that converts an angle in radians to degrees. The method takes a single parameter, an angle in radians, and returns the equivalent angle in degrees. In this article, we’ll explore how to use the degrees() method in Python 3.
Syntax
The syntax for the degrees() method is as follows:
import math
math.degrees(x)
Where x
is the angle in radians.
Parameters
The degrees() method takes a single parameter, x
, which is the angle in radians.
Return Value
The degrees() method returns the equivalent angle in degrees.
Examples
Here are some examples of how to use the degrees() method in Python 3:
Example 1: Convert 1 Radian to Degrees
import math
x = 1.0 # 1 Radian
result = math.degrees(x)
print(result)
Output:
57.29577951308232
Example 2: Convert Multiple Radians to Degrees
import math
angles = [0.523599, 1.047198, 1.5708, 2.0944, 2.61799]
for x in angles:
result = math.degrees(x)
print(result)
Output:
30.000001335728684
59.99999866427134
89.99999949999999
119.99999929446698
149.99999866552495
In the above example, we convert a list of five angles from radians to degrees using a for loop.
Conclusion
The degrees() method is a useful built-in function in Python 3 for converting angles from radians to degrees. By using this method, we can avoid the need to manually convert radians to degrees in our code. Remember to import the math module before using the degrees() method in your Python scripts.