Import System and Standard Library
Learn import syntax, aliases, and explore powerful built-in standard modules.
Learning objectives
- Import modules using import math, from math import sqrt, and import math as m
- Understand __name__ == "__main__" idiom for script entry points
Lesson material
Standard Library Imports
Python ships with a rich standard library.
Example code
import math
from random import choice
print("Pi:", round(math.pi, 2))
print("Random choice:", choice(["Python", "Rust", "Go"]))
Practice exercise: Math Module Functions
Import the `math` module and calculate the square root of `16` using `math.sqrt()`. Print the result cast as integer.