Skip to content

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
Step-by-step guide: how to use learn-pythonInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Clone and build from source

    You'll need: Python 3 · pip

    Clone the repository

    git clone https://github.com/trekhleb/learn-python.git

    Install dependencies

    pip install -r requirements.txt
  2. 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. 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

ProjectStarsTypeLevelUpdatedBest for
learn-python (this)18.5kLearning resourcebeginner7 months agoBeginners who want to learn Python syntax by reading and running examples
professional-programming51.7kCurated listbeginner10 days agoSoftware engineers who want to build professional habits and broader engineering judgment
pure-bash-bible41.7kLearning resourceintermediate2.9 years agoBash scripters who want fewer external dependencies in their scripts
java8-tutorial16.7kLearning resourcebeginner3.2 years agoJava developers who work on older Java code and want to learn Java 8 features
night12.3kLearning resourcebeginner2 months agoGo developers who want to deepen their understanding of the language and its source code
Web-Dev-For-Beginners97.1kLearning resourcebeginner5 days agoComplete 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.