
learn-python
A collection of annotated Python scripts with runnable assertions, organized by topic.
- Stars
- 18.5k
- Forks
- 3k
- Licence
- MIT
- Language
- Python
- Last update
- 7 months ago
- Type
- Learning resource
What it is
This repository is a set of Python scripts split by topic, such as variables, lists, classes and files. Each script includes explanations in comments and docstrings, plus assertions that show the expected output of code. You can read it as a cheatsheet or run and edit the code to see how it behaves.
- Read the examples for a topic such as list comprehensions or decorators to recall the syntax
- Run the pytest suite to confirm the assertions pass on your machine
- Edit a script and add your own assertions to test your understanding
- Use the linting setup to check code against the Python style guide
Great for
- Beginners who want to learn Python syntax by reading and running examples
- People who want a quick reference for standard Python statements and built-in constructs
- Learners who prefer hands-on practice by changing code and running tests
- Developers who want to check their code style with a linter alongside the examples
Not ideal for
- Readers looking for a complete course with projects, since the README describes topic-by-topic examples rather than a structured curriculum
- People who need advanced or domain-specific Python topics, since the table of contents covers core language and standard library basics
- Those who do not want to install Python and pytest, since running the tests requires a local setup
How to get it
- 1
Clone and build from source
You'll need: Python 3 · pip
Clone the repository
git clone https://github.com/trekhleb/learn-python.gitInstall dependencies
pip install -r requirements.txt - 2
Run it
- Clone the repository and move into its folder
- Install dependencies with pip install -r requirements.txt
- Open a topic file such as src/data_types/test_lists.py and read the comments
- Run the tests with pytest to check the assertions
- 3
Get the most out of it
- Read the docstring link at the top of each script for further reading
- Follow the table of contents in order from Getting Started to User input
- Modify examples and add new assertions to see how behavior changes
- Run the linter mentioned in the README to check your code style
Downloads
Strengths
- Each example pairs code with assertions that show the expected result
- Topics are organized in a clear table of contents from basics to standard libraries
- Free and open source under the MIT license
Trade-offs
- The README is truncated in this analysis, so some setup and testing details may be missing
- Coverage is limited to core Python and a brief tour of standard libraries
- Requires a local Python 3 environment and pip to run the tests
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| learn-python (this) | 18.5k | Learning resource | beginner | 7 months ago | Beginners who want to learn Python syntax by reading and running examples |
| professional-programming | 51.7k | Curated list | beginner | 10 days ago | Software engineers who want to build professional habits and broader engineering judgment |
| pure-bash-bible | 41.7k | Learning resource | intermediate | 2.9 years ago | Bash scripters who want fewer external dependencies in their scripts |
| java8-tutorial | 16.7k | Learning resource | beginner | 3.2 years ago | Java developers who work on older Java code and want to learn Java 8 features |
| night | 12.3k | Learning resource | beginner | 2 months ago | Go developers who want to deepen their understanding of the language and its source code |
| Web-Dev-For-Beginners | 97.1k | Learning resource | beginner | 5 days ago | Complete beginners who want a structured, self-paced path into web development |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.