Python 3.14 ·
✓ verified by execution on 2026-07-23
Standard Library Tour
The Python Standard Library is a collection of modules that come pre-installed with Python.
The Math Module
The math module gives you common mathematical functions and constants — square roots, trigonometry, logarithms, pi, and more — backed by your platform’s fast C math library.
python
import mathprint(math.sqrt(25.0))
Output
5.0
Your output
The math functions don’t work with complex numbers. Ask for the square root of a negative number and you get a ValueError, not a complex result — for that you’d use the cmath module instead:
python
import mathtry: math.sqrt(-1.0)except ValueError as e: print('ValueError:', e)
Output
ValueError: expected a nonnegative input, got -1.0
Your output
The Random Module
The random module produces pseudo-random numbers — they look random but come from a deterministic algorithm. That’s why seeding it with random.seed(42) makes the sequence repeatable, which is exactly what you want when writing tests.
The string module defines handy constants for common groups of characters — like every digit, or every letter:
python
import stringprint(string.digits)
Output
0123456789
Your output
string.ascii_letters is simply the lowercase letters followed by the uppercase ones — 52 in all:
python
import stringprint(len(string.ascii_letters))
Output
52
Your output
Edge Cases
Random numbers from the random module shouldn’t be used for cryptography; use the secrets module instead.
Floating point math functions in the math module can be subject to precision issues.
Check yourself
The random module generates truly unpredictable random numbers suitable for security.
Reveal answer
It generates pseudo-random numbers that are predictable. For security, the secrets module must be used. — It generates pseudo-random numbers that are predictable. For security, the secrets module must be used.
math.sqrt(-1) will return a complex number '1j'.
Reveal answer
It raises a ValueError. The cmath module is required for complex numbers. — It raises a ValueError. The cmath module is required for complex numbers.
You can use string.ascii_letters without importing the string module.
Reveal answer
They live in the string module namespace and require an explicit import. — They live in the string module namespace and require an explicit import.
Standard library modules need to be installed with pip.
Reveal answer
They are built-in and shipped with Python by default. — They are built-in and shipped with Python by default.
Challenges
Challenge 1 +25 XP
Import the math module and use `math.hypot()` to calculate the hypotenuse of a right triangle with sides 3 and 4. Print the result.
python
Test 1 — expects "5.0"
Need a hint? (−25% XP)
Check the math documentation for hypot.
Show solution (0 XP)
import mathprint(math.hypot(3, 4))
Challenge 2 +25 XP
Import `random` and `string`. Set the random seed to 42 using `random.seed(42)`. Choose a random letter from `string.ascii_uppercase` and print it.