Errors, files and libraries · Lesson 18 of 25
Modules and the standard library
Import existing tools and organize files.
8 minutes2 games
A module is often a Python file. import math gives access to math.sqrt; from math import sqrt imports one name. The standard library ships with Python; external packages are installed in the project environment.
Python
import math
from collections import Counter
print(math.isqrt(81))
counts = Counter("banana")
print(counts["a"])
print(sorted(counts.items()))| Tool | Use |
|---|---|
| Mathematics |
| Count occurrences |
| Filesystem paths |
| JSON encoding and decoding |
Complete the code
Import math and print a square root.
math print(math.(25))
Exercise
Use Counter and print the count of tea.
Expected output: 2
Python
from collections import Counter orders = ["tea", "coffee", "tea"]
Learn more from
Played 0 of 2 games
Sign in to save your progress and earn XP.