trekhleb/learn-python: a pytest suite that is also the tutorial, pinned to 2018 tooling
📚 Playground and cheatsheet for learning Python. Collection of Python scripts that are split by topics and contain code examples with explanations.
At a glance
- What is it?
- This repository teaches Python by being a test suite. Every example is a function whose name starts with the test prefix, the expected behaviour is an assertion, and the file template is printed in the README so a reader can see the shape before opening anything. Two details are worth knowing before you start: the lint and test toolchain is pinned to exact versions from 2017 and 2018, and the visible build badge points at a service that no longer runs.
- Who is it for?
- Use this repository if you want to learn the core language syntax with examples you can edit and immediately check, because the assertions are the expected output and you do not have to run anything to see the answer. Do not use it as a reference for tooling or for a modern standard library tour, because the contents stop at the language and a short standard library section, and the test and lint tools are pinned to releases from 2017 and 2018.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Activity is slowing. The repository last received commits 7 months ago.
- What is it written in?
- Mainly Python, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 15, 2026, and from our analysis. They are not legal advice.
Star history
- trekhleb/learn-python18,525 ★ · +224
| Repository | 2026-09-21 | 2026-11-15 |
|---|---|---|
| trekhleb/learn-python | 18.3k | 18.5k |
224 Stars in the last 55 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
The expected output is an assertion, so the cheatsheet needs no run
The repository calls itself two things, a playground and a cheatsheet, and it gives a different reason for each.
As a cheatsheet, you come back to a topic to recap the syntax of standard statements and constructions. The stated reason it works without launching anything is that the code is full of assertions, so the expected output of a function or a statement is visible in the file.
As a playground, you change the code or add assertions to see what happens, then run the tests and the linter. The stated benefit is that the examples are interactive and that the code stays close to the style guide from the beginning.
The mechanism is in the file template the README prints, which is the single most useful thing in it. A module docstring carries the topic name and a link for further reading. Then come functions whose names begin with the test prefix, each with its own docstring explaining a subtopic, and inline comments that explain each action.
"""Lists <--- Name of the topic here
# @see: https://www.learnpython.org/en/Lists <-- Link to further readings goes here
Here might go more detailed explanation of the current topic (i.e. general info about Lists).
"""
def test_list_type():
"""Explanation of sub-topic goes here.So every script in the repository is a runnable test module, and the tutorial text is a docstring. A reader who edits a line and reruns finds out immediately whether they understood it, which is the thing a printed cheatsheet cannot do.
Every dependency is an exact pin, and they are all from 2017 and 2018
The requirements file has sixteen entries and not one of them uses a range or a floor. They are all exact, and they are all old.
The test runner is pinned to a version released in 2018. The style checker is pinned to a version from 2017. The static analyser, the import sorter and their transitive dependencies are pinned to versions from the same two years, down to the small utility packages they pull in.
So the toolchain that checks this tutorial predates most of the Python the tutorial teaches. That is defensible for a teaching repository whose scripts avoid anything version sensitive, and it is a real obstacle for a reader on a current interpreter, where an exact pin from 2018 may not install or may not run.
There is also a hand written lockfile shape here. Pinning a lint stack means pinning its whole dependency graph by hand, which is why the list contains packages nobody would choose deliberately, and which have to be updated together when one of them needs to move.
The practical consequence is that a reader who wants to run the tests on a new Python may spend their first afternoon in a resolver rather than in Python. The examples themselves are plain enough to read without any of it installed, which is why the cheatsheet half of the project still works.
The build badge points at a service that no longer runs, and the site is static
Two repository facts sit next to each other at the top of the readme, and they are the same fact from different angles.
The build status badge points at a hosted continuous integration service whose domain is still in the readme, and the repository root still carries that service's configuration file.
The site itself is a static pages build: the root carries a configuration file in the format that static site generators read, next to the readme translations, so the readme is rendered by a generator rather than served from the repository.
The consequence for a reader is that the visible health signal is a badge that stopped updating years ago, and the useful signal, which is whether the examples still pass, is something you find out by running them. For a tutorial whose central claim is that its examples are executable, that is an odd place to be.
The rest of the root is conventional: a gitignore, a code of conduct, the licence, five readme files, and the source directory that holds the scripts.
One contents entry is misspelled and two are markdown rather than Python
The table of contents is a set of numbered groups, at least eleven, and it is a list of file paths, which makes it a useful place to look for the shape of the project.
The first group holds two markdown files and one Python file. The two prose entries, on what Python is and on its syntax, are documents; the third, on variables, is a script like everything after it. So the first topic in the repository is partly prose that is not under the test runner.
Further down, the assignment operators entry points at a file whose name is misspelled: the file is `test_assigment.py`, missing the n before the m. Every other file in that group is spelled correctly, so it is one file.
After that the convention is exact. One directory per topic under the source root, named after the topic, and inside it files named for the concept with the test prefix, each carrying the operator or keyword in backticks so the reader can see the syntax without opening the file.
The two irregularities are harmless for a human and slightly untidy for anything that parses the readme, and they are the sort of thing that survives because a document of this size is edited by hand.
The contents are the language, in the order the language is taught
The first eleven groups are, in order: getting started, operators, data types, control flow, functions, classes, modules, errors and exceptions, files, additions, and a brief tour of the standard libraries.
Within a group the order is the order a tutorial would use. Operators are split into seven files, arithmetic, bitwise, assignment, comparison, logical, identity, membership, and each one lists its symbols in backticks. Functions is the largest visible group with ten entries, running from definition and return through scopes, default arguments, keyword arguments, argument unpacking, lambdas, docstrings, annotations and decorators. Classes has seven, from definition through inheritance to multiple inheritance. The eleventh group starts with serialization and file wildcards.
The README also points to a companion repository of interactive machine learning experiments by the same author.
So this is a syntax course with a runnable test harness, and anyone arriving for a production Python answer will find a curriculum instead.
The readme opens with a war appeal, permanently, above the project description
The top of the readme, above the title's context and before the description, is a block in capitals stating that Ukraine is being attacked, that civilians are being killed and that residential areas are being bombed. It is followed by three donation links, to two charity foundations and a national bank special account, and then links to a war information site and to the country's foreign ministry account.
It is not a banner image and it is not hidden behind a details element. It is the first thing a visitor reads in the English readme.
The observation is about the repository rather than the project. A permanent editorial statement at the top of a code repository is a choice an author has made, and it is consistent with the author's other work, since the description also points readers to a second repository of experiments. But it is the first signal an evaluator sees, and it tells you that the readme is maintained as a personal page as well as a document.
Everything below that block is what you would expect from a careful teaching repository: a file template, a five step usage loop, and a contents list with file paths.
Editorial conclusion
Use this repository if you want to learn the core language syntax with examples you can edit and immediately check, because the assertions are the expected output and you do not have to run anything to see the answer. Do not use it as a reference for tooling or for a modern standard library tour, because the contents stop at the language and a short standard library section, and the test and lint tools are pinned to releases from 2017 and 2018. Check three things before you rely on it: whether the pinned toolchain installs on your interpreter, since every dependency is an exact pin and a lint stack from that era does not always build on a current Python; which topic you actually need, because the topic groups cover the language rather than the ecosystem; and whether the build status matters to you, since the badge points at a discontinued service and the site is a static pages build. The license is MIT, the readme exists in four translations besides the original, and the last push was 2026-04-06.
Frequently asked questions
Can I teach myself Python?
The repository's own answer is that it is a playground and a cheatsheet. The stated loop is: find the topic you want, read the comments and the documentation linked in the file's docstring, look at the code examples and their assertions for expected output, change the code or add assertions, then run the tests and the linter. The readme exists in Portuguese, Spanish, Traditional Chinese and Ukrainian besides the original.
Is Python easy to learn?
The repository makes no claim about difficulty. It organises the language into numbered topic groups and puts the expected output of each example into assertions, so a reader can check an answer without running anything. Every dependency is pinned to an exact version, and the test runner and style checker are pinned to releases from 2017 and 2018.
How long will it take to learn Python?
No estimate is given. The contents cover what Python is and its syntax, then operators, data types, control flow, functions, classes, modules, errors and exceptions, files, a few additions, and a short tour of the standard libraries. The project is MIT licensed and the last commit was 2026-04-06.
Can ChatGPT teach you Python?
The README does not discuss assistants. The closest thing it points at is a companion repository of interactive machine learning experiments by the same author. The stated purpose of this repository is a playground where you can change or add code and check it with assertions, and a cheatsheet for recapping standard statements and constructions.
how to use learn python
Each script follows one structure: a module docstring naming the topic and linking to further reading, then functions whose names begin with the test prefix, each with a docstring for its subtopic and inline comments explaining each action. You find the topic in the contents, read those comments, look at the examples and assertions, change the code, and then run the tests and the linter.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/trekhleb-learn-python)Star history chart for your README
[](https://hysenlabs.com/projects/trekhleb-learn-python)Was this useful?