explaingit

trekhleb/learn-python

Analysis updated 2026-06-24

17,955PythonAudience · developerComplexity · 1/5Setup · easy

TLDR

A topic-by-topic collection of runnable Python scripts that teach the language by example and double as a cheat sheet you can come back to.

Mindmap

mindmap
  root((learn-python))
    What it does
      Topic-by-topic scripts
      Code with assertions
      Cheat sheet
    Tech stack
      Python 3
      pytest
      Linting
    Use cases
      Learn Python basics
      Quick syntax lookup
      Practice playground
    Audience
      Beginners
      Self-learners
      Returning Pythonistas
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

What do people build with it?

USE CASE 1

Learn Python from scratch by editing and running small example scripts.

USE CASE 2

Use the repo as a quick cheat sheet to look up forgotten syntax.

USE CASE 3

Practice writing Python by adding your own assertions to existing examples.

USE CASE 4

Run the linter to check your code follows Python style conventions.

What is it built with?

Pythonpytest

How does it compare?

trekhleb/learn-pythonsczhou/codeformerfastapi/sqlmodel
Stars17,95517,96017,928
LanguagePythonPythonPython
Setup difficultyeasyhardeasy
Complexity1/54/52/5
Audiencedeveloperresearcherdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you get it running?

Difficulty · easy Time to first run · 5min

Just needs Python 3 installed, clone and run any script.

License is not stated in the explanation.

In plain English

learn-python is a collection of Python scripts designed to teach you the Python programming language through hands-on examples and a built-in cheat sheet. Python is a popular, beginner-friendly programming language used for everything from web apps to data analysis. The repository is organized by topic, covering things like variables, data types, control flow (if/for/while statements), functions, classes, error handling, file reading, and parts of Python's standard library. Each script follows the same pattern: a brief explanation at the top, then code examples paired with assertions (checks that confirm what the output should be), so you can see exactly what each piece of code does without having to run it yourself. The "playground" aspect means you can open any script, tweak the code, add your own examples, and run the built-in tests to see if your changes work. This makes learning interactive rather than passive, you experiment directly in the code instead of just reading about it. The "cheatsheet" aspect means you can return later to quickly look up Python syntax you've forgotten, like how lists work or how to handle exceptions. The repository is written in Python 3 and covers beginner-to-intermediate ground. You would use it if you are new to Python and want structured, runnable examples to practice with, or if you already know some Python and need a quick reference for syntax. It also supports linting so you can check whether your code follows Python style conventions.

Copy-paste prompts

Prompt 1
I'm a total Python beginner. Walk me through the order I should read the scripts in trekhleb/learn-python, variables first, then what?
Prompt 2
Take the 'functions' script from learn-python and add three new examples showing default arguments, keyword arguments, and *args. Include assertions.
Prompt 3
Explain how the assertions inside each learn-python script work and how I'd run all of them at once with pytest.
Prompt 4
Give me a 10-line cheat sheet of Python list comprehensions, in the same comment-then-code-then-assertion style learn-python uses.
Prompt 5
I know JavaScript but not Python. Map the learn-python topic list onto JS equivalents so I can skim what I already understand.

Frequently asked questions

What is learn-python?

A topic-by-topic collection of runnable Python scripts that teach the language by example and double as a cheat sheet you can come back to.

What language is learn-python written in?

Mainly Python. The stack also includes Python, pytest.

What license does learn-python use?

License is not stated in the explanation.

How hard is learn-python to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is learn-python for?

Mainly developer.

Open on GitHub → Explain another repo

This repo across BitVibe Labs

Scan in gitsafehub Deploy in gitdeployhub trekhleb on gitmyhub

Verify against the repo before relying on details.