Python math.radians
In Python, math.radians converts an angle from degrees to radians by multiplying by π/180. A quarter turn is 90 degrees, or π/2 radians.
A simple example
math.radians
- Start with 180 degrees
- Do this Convert a half-turn to radians
- Result π radians
Syntax
math.radians(degrees)
Run these examples in Python
Save one example at a time as lesson.py. Use Python 3.9 or later.
python3 lesson.pyConvert a half turn into radians
A drawing program describes the rotation of a wheel as a half turn. Its math routines consume radians, so convert that familiar rotation before passing it to the geometry code.
import math
degrees = 180.0
print(f"{math.radians(degrees):.3f}")
3.142
A half turn is 180 degrees, approximately 3.142 radians.
Feed a right angle into a drawing tool
An illustration tool receives a turn measured in degrees while its geometry routines expect radians. Convert the angle before using it to position a line on the drawing.
import math
angle = 90.0
print(f"{math.radians(angle):.3f}")
1.571
The drawing tool expects radians. Ninety degrees converts to approximately 1.571.
Animate a clock hand
An animator moves a hand thirty degrees around a dial. The rendering library expects radians for the rotation.
Using 30 gives 0.524 rad for this measurement.
What to watch for
The displayed result is rounded. Keep the full returned value when doing further calculations.