Everything you need to learn Python in one place: a 23-chapter course from
Hello, world!to packaging, 121 exercises with solutions, 12 complete projects, and a library of 280+ runnable algorithm and deep-dive samples.
Every file in this repository is a self-contained lesson: open it, read it top to bottom, and run it with one command. Nothing to install except Python itself. There are no third-party packages anywhere.
- Why LearnPython?
- Quick start
- Where to start
- How to study
- The course (basics/)
- Exercises
- Projects
- Going deeper
- A taste of the code
- How this repo is organized
- Repository conventions
- Contributing
- Inspiration
- License
Most tutorials either bury you in features before you can write a program, or hand you a finished application with no explanation of its pieces. LearnPython takes a third path, one concept per file, and gives you the whole journey in one place:
- Learn: a numbered course in
basics/, with plain-English explanations in every file. - Practise: an exercise file for every chapter in
exercises/, which checks your answers and has worked solutions. - Build: complete programs in
projects/that combine many chapters. - Go deeper: dense deep dives in
advanced/and 29 categories of classic algorithms.
Every file runs, and CI runs every one of them on Python 3.12 and 3.13 on each push.
-
Install Python from python.org/downloads. Any CPython
3.12or newer works. -
Clone the repo:
git clone https://github.com/thejesh23/LearnPython.git cd LearnPython -
Run your first lesson:
python3 basics/00_hello_world/hello_world.py
That's the whole workflow. There is no build step, no virtualenv and no pip install. DIRECTORY.md lists every runnable file.
| You are... | Start at | Then |
|---|---|---|
| New to programming | basics/00_hello_world/ |
Go through the chapters in order, doing each chapter's exercises before moving on. |
| Coming from another language (JavaScript, Java, C#, Go, Dart...) | basics/02_types/ |
Skim chapters 02–09 for Python's idioms (comprehensions, generators, decorators, context managers, match), then dig into 10–22. |
| Already writing Python | basics/15_typing/ or any chapter from 13 on |
Fill gaps with the later chapters, the projects and advanced/. |
| Preparing for interviews or CS classes | The algorithm categories | Each algorithm is one small, focused file that checks itself. |
Each chapter follows the same loop:
- Read the chapter's
README.md. It lists the files in reading order. - Run each file and read it alongside its output. Change something and run it again.
- Practise with the chapter's exercise file until every line says
[solved]. - Build a project once you reach the chapter it needs. See the "Ready after" column in
projects/. - Go deeper with the chapter's links into
advanced/and the algorithm folders, when you're curious.
Each chapter folder has its own README with the reading order, the exercises, and links for going deeper.
| # | Chapter | You'll learn |
|---|---|---|
| 00 | Hello, world | Running a script, print, the __main__ guard |
| 01 | Variables | Assignment, naming, constants by convention, unpacking |
| 02 | Types | int, float, str, bool, None, conversions, type hints, Decimal and Fraction |
| 03 | Operators | Arithmetic, comparison, logic, identity and membership, the walrus |
| 04 | Strings | Slicing, methods, f-strings, raw strings, text tools, Unicode and bytes |
| 05 | Control flow | if, for, while, break/continue/else, match |
| 06 | Functions | Parameters of every kind, docstrings, lambdas, higher-order functions, closures, decorators, recursion |
| 07 | Collections | Lists, tuples, dicts, sets, comprehensions, sorting, copying, stacks and queues |
| 08 | Iterators and generators | The iterator protocol, yield, itertools, lazy pipelines, yield from and send |
| # | Chapter | You'll learn |
|---|---|---|
| 09 | Classes | Classes, properties, dunder methods, dataclasses, enums, inheritance vs composition, protocols, slots, descriptors, metaclasses |
| 10 | Async | async/await, tasks, async generators and queues, timeouts, running blocking code |
| 11 | Errors | try/except/else/finally, raising, custom exceptions, exception groups, warnings, debugging |
| 12 | Modules and I/O | Imports, pathlib, with, contextlib, JSON, CSV, config files |
| 13 | The standard library | collections, functools, datetime, re, logging |
| 14 | Testing | assert, doctest, unittest, unittest.mock |
| # | Chapter | You'll learn |
|---|---|---|
| 15 | Typing | Generics (3.12 syntax), TypedDict, Literal, Callable, @overload, NewType, hints at runtime |
| 16 | Threads and processes | Threads, race conditions and locks, queues, thread and process pools, choosing a concurrency model |
| 17 | The OS and the command line | argparse, environment variables, subprocess, files and folders, exit codes and signals |
| 18 | Data and storage | SQLite, pickle (and its dangers), binary data with struct, archives, hashing and secrets |
| 19 | Networking | URLs, sockets, HTTP servers and clients, a JSON API client with retries |
| 20 | Performance | timeit, cProfile, tracemalloc, choosing data structures, faster idioms |
| 21 | Pythonic code | The Zen of Python, idiomatic loops, EAFP vs LBYL, common mistakes, style and PEP 8 |
| 22 | Packaging and projects | Virtual environments, installing packages, pyproject.toml, project layout and tests |
exercises/ has one file per chapter, 121 tasks in all. Each task is a stub with a docstring and a test underneath:
$ python3 exercises/ch07_collections.py
1. squares_of_evens [solved]
2. unique_in_order [not yet] unique_in_order(['b', 'a', 'b', 'c', 'a']) returned ['a', 'b', 'c'], expected ['b', 'a', 'c']
3. word_counts [todo] not attempted
Every exercise file has a matching file in exercises/solutions/ that runs the same tests against an idiomatic answer.
projects/ has twelve complete programs, from a quiz game and a text adventure to an expense tracker on SQLite and a URL shortener with its own web server. Each one lists the chapters it draws on, runs a scripted demo by default, and was built up commit by commit, so its history replays how it was made.
advanced/: 38 dense single-file deep dives for readers who know the basics, such as descriptors, metaclasses, the GIL, weakrefs, bytecode, and a mini event loop.- Algorithms: 29 categories, each with one algorithm per file and a
main()that checks it. Each category also has a*_kitpackage that puts its samples together behind a clean API.
arrays/ · sorts/ · searches/ · strings/ · maths/ · recursion/ · data_structures/ · linked_lists/ · trees/ · matrix/ · dynamic_programming/ · graphs/ · greedy/ · backtracking/ · bit_manipulation/ · number_theory/ · numeric/ · geometry/ · conversions/ · ciphers/ · crypto/ · compression/ · concurrency/ · distributed/ · machine_learning/ · probabilistic/ · parsers/ · project_euler/ · puzzles/
Your first Python program, from basics/00_hello_world/hello_world.py:
print("Hello, world!")Structural pattern matching, from chapter 05:
def describe(n: int) -> str:
match n:
case 0:
return "zero"
case 1 | 2 | 3:
return "small"
case _ if n < 0:
return "negative"
case _:
return "large or unusual"A generic stack, using the 3.12 syntax from chapter 15:
class Stack[T]:
def __init__(self) -> None:
self._items: list[T] = []
def push(self, value: T) -> None:
self._items.append(value)
def pop(self) -> T:
return self._items.pop()LearnPython/
├── basics/ the course: chapters 00_ ... 22_, each with a README
├── exercises/ one practice file per chapter
│ └── solutions/ worked answers that run the same tests
├── projects/ complete programs that combine many chapters
├── advanced/ single-file deep dives
├── sorts/ graphs/ ... 29 algorithm categories, each with a *_kit package
├── DIRECTORY.md flat index of every runnable file
├── CONTRIBUTING.md file and commit conventions
├── LICENSE MIT
└── README.md you are here
- One concept per file. If it can be split, split it.
- Small commits. A file grows across a few commits, one idea at a time, and every commit runs.
git log --follow <file>replays how it was built. - Every file runs. Each file has a
main()you can run directly. - Zero dependencies. Everything runs on the standard library alone.
basics/files teach. Their comments explain the what and the why.- Algorithm files stay clean. They only comment when the why is non-obvious.
Full details in CONTRIBUTING.md.
New samples, exercises and projects are always welcome. Please read CONTRIBUTING.md first. The short version:
- One concept per file. If it can be split, split it.
- Small commits. Message format:
Add: <path> — <one-line what it teaches>. - Run the file before you submit it.
- Update
DIRECTORY.mdwhen you add files (python3 .github/scripts/gen_directory.py).
- TheAlgorithms/Python: the model for the algorithm categories.
- docs.python.org/3/tutorial: the canonical reference for every language feature covered in
basics/. - LearnDart: the sibling repository for Dart.
Released under the MIT License.