fuckingpython.lol

Learn fucking Python

A free Python tutorial for people who would rather write code than read about it. Short lessons, each a handful of small programs you run yourself, explained the way a friend would explain them at 2 a.m. while your code refuses to work.

Every example ran on real Pythons, 3.9 to 3.15, and the output is pasted, not imagined. When something breaks, and it will, the second half of the site explains every error message you are about to meet.

The Python lessons, in order

  1. Lesson 1Hello, worldInstall the thing, print a greeting, break it on purpose. The traditional start, minus the ceremony.
  2. Lesson 2Variables and typesStick a name on a value, ask Python what type it is, then meet the NameError you will see a thousand times.
  3. Lesson 3StringsGlue text together, chop it into slices, and find out why "Age: " + 30 makes Python throw a fit.
  4. Lesson 4Numbers and mathSplit a pizza, round a price, and find out why 0.1 + 0.2 is a fucking mess in almost every language.
  5. Lesson 5if, elif, elseYour code starts making its own decisions. Bad ones, mostly, but its own.
  6. Lesson 6ListsOne variable, a whole pile of stuff. The first item is number zero, and you'll forget that at least twice.
  7. Lesson 7LoopsWrite the boring part once, let the computer do it ten thousand times. Then learn how to make it stop.
  8. Lesson 8FunctionsName a chunk of code, call it whenever. Also: why your function quietly handed back jack shit.
  9. Lesson 9DictionariesLabels instead of positions. Plus KeyError, a dict's way of asking who the hell that is supposed to be.
  10. Lesson 10Errors and try/exceptRead the wall of error text bottom up, catch what you expected, and let the rest crash loudly as hell.
  11. Lesson 11FilesYour programs finally remember things between runs. Also: which single letter shreds a file.
  12. Lesson 12Modules, imports and pipBorrow code from Python, from your past self and from strangers on the internet. Politely, with a venv.
  13. Lesson 13ClassesMake your own types, learn what the hell self is, then forget it twice, like everybody does.

When it breaks: Python error messages, explained

One page per message: the code that raises it, what it means, the fix, and how every Python from 3.9 to 3.15 words it.

TypeError

AttributeError

ValueError

SyntaxError

IndentationError

TabError

NameError

UnboundLocalError

ModuleNotFoundError

ImportError

IndexError

KeyError

RecursionError

pip

Before Python starts

What is new in Python error messages