Free lab Real Python 3. Zero installs. Your code stays in this browser. Open the playground

Standard Library Power Tour

16 min 35 XP
Study loop Read Predict Run Tweak Prove Review
Lesson 5 of 5 · View course roadmap
Step 1

Learn the idea

Python ships "batteries included" — a huge standard library. The modules you'll reach for weekly:

  • jsonjson.dumps(obj) / json.loads(text): convert between Python and JSON
  • datetime — dates, times, differences: date.today(), timedelta(days=7)
  • randomchoice, shuffle, randint
  • collections.Counter — count things in one line
  • pathlib.Path — modern file paths

Counter deserves special love: Counter("mississippi").most_common(2)[('i', 4), ('s', 4)]. Before writing a loop, ask: "does the stdlib already do this?" It usually does.

Where you'll use this

'Batteries included' is why Python won ops and data: json for every API, datetime for every schedule, csv for every export, Counter for every 'top N' feature — zero installs required.

Common mistakes

  • Rebuilding what exists: hand-rolled JSON parsing, manual date math across month boundaries, DIY counting loops — the stdlib version is tested against edge cases yours will miss.
  • json.load vs json.loads (and dump/dumps): the s means string, the plain one takes a file object.
  • random for anything security-related — passwords and tokens need the secrets module.

Pro tip

Before writing any utility function, spend 30 seconds checking: does itertools, collections, functools or pathlib already do this? The answer is yes more often than any other language.

Step 2

Try it yourself

Blank · autosaved

The lesson example is loaded and ready — press Run, then change something and run it again. Breaking it is part of learning. Want a clean slate? Tap “New blank”.

PYexample.py
+ Enter to run
Output appears here…
Step 3

Pass the challenge +35 XP

Blank · autosaved

Use Counter to find the two most common letters in "abracadabra" and print each as letter count on its own line.

Target output
a 5
b 2
PYchallenge.py
Run your code to check it…
Step 4

Check your understanding

1. json.loads() converts…
Last step

Your notes (saved on this device)

Tip: use and to move between lessons, K to search everything.

Your next ten minutes

Write Python that does something useful.

Start free. No install, no card, no passive video marathon.

Start learning free → Explore the path