typestar

Language basics

72 steps in 13 sets of Python.

Everything you need before the interesting parts. Variables and the handful of types Python has, strings and the methods that do most of the work, flow control, the four collections, functions, and classes. Then a second pass that goes deeper on the same ground: sets and mappings, number and text handling, errors beyond a bare try, and how expressions evaluate.

It is the longest tour here at 72 steps, and deliberately so. Most of what you type in Python for the rest of your life is in this vocabulary. The Encore is complete programs rather than fragments, so you finish by typing something that actually runs.

Start this tour

Variables & types

Strings

Flow control

Collections

Functions

Classes

Iterators, errors & files

Algorithms

Sets & mappings

  • Frozen setsAn immutable set, so it can be a dict key or live inside another set.
  • Dictionary viewskeys, values and items are live views, not copies.
  • Sorting by a keyOne pass, one key function, and a stable order you can rely on.

Numbers & text

Errors in depth

  • The exception hierarchyCatch the narrowest class that covers what you can actually handle.
  • else and finallyFour blocks, four jobs: try, except, else for success, finally for cleanup.
  • File modesRead, write, append, exclusive and binary — and what each one destroys.

Expressions

Encore

  • fetch_json.pyFetch a JSON API and pretty-print it, no dependencies.
  • word_freq.pyA complete CLI tool: read a file, count words, print a report.
  • todo_cli.pyA complete CLI todo list persisting to JSON.
  • grep_lite.pyA minimal grep: find lines matching a pattern across files.
  • csv_stats.pySummary statistics for one CSV column, stdlib only.

The other Python tours