capypad
0 day streak
python / beginner
Snippet

Importing Modules

The import statement allows you to use code from external libraries or modules, such as the built-in math module for calculations.

snippet.py
python
1
2
3
import math
result = math.sqrt(16)
print(result)
Breakdown
1
import math
Loads the mathematical functions module into your current script.
2
result = math.sqrt(16)
Calls the 'sqrt' (square root) function from the math module to calculate the root of 16.
3
print(result)
Outputs the calculated result (4.0) to the console.