Python 3 – Number radians() Method
In Python, radians() is a built-in method which is used to convert the given angle from degrees to radians. A radian is a unit of measurement for angles, which is equal to the angle at the center of a circle, whose arc has a length equal to the radius of a circle.
To use the radians() method, you need to first import the math module in your program. The syntax of the radians() method is as follows:
import math
radians = math.radians(degrees)
Here, degrees is the angle in degrees, which you want to convert into radians. The method converts the given angle from degrees to radians and returns the value in radians.
Let’s see an example below for converting degrees to radians.
import math
# Convert 180 degrees to radians
radians = math.radians(180)
print("Radians:", radians)
Output:
Radians: 3.141592653589793
In the above code, we have imported the math module and used the radians() method to convert the value of 180 degrees to radians. The resulting value is stored in the variable radians, which is then printed to the console.
We can also use the radians() method to convert angles in other formats, such as gradients and cycles.
import math
# Convert 100 gradients to radians
radians = math.radians(100 * 0.9)
print("Radians:", radians)
Output:
Radians: 1.5707963267948966
In the above code, we have converted the value of 100 gradients to radians by multiplying it with 0.9 and passing it to the radians() method.
The radians() method can also handle negative angles, which represent angles that are measured in the opposite direction to the positive x-axis.
import math
# Convert -90 degrees to radians
radians = math.radians(-90)
print("Radians:", radians)
Output:
Radians: -1.5707963267948966
In the above code, we have used the radians() method to convert the value of -90 degrees to radians. The resulting value is stored in the variable radians, which is then printed to the console.
Conclusion
The radians() method is a useful method in Python for converting angles in degrees to radians. This method is part of the built-in math module in Python, which provides a wide range of mathematical functions and constants. By using the radians() method, you can easily convert angles from degrees to radians, making it easier to perform complex mathematical calculations in Python.