python / beginner
Snippet
Accessing Mathematical Constants
The 'math' module provides access to important mathematical constants like Pi, which is more accurate than typing it manually.
snippet.py
1
2
3
4
5
import mathradius = 5area = math.pi * radius * radiusprint(area)
Breakdown
1
import math
Loads the built-in math library into the script.
2
math.pi
Accesses the constant value of Pi (approximately 3.14159).