capypad
0 day streak
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
python
1
2
3
4
5
import math
 
radius = 5
area = math.pi * radius * radius
print(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).