A complete, runnable Python course in 20 chapters, taking a reader from their first literal to a tested, packaged data pipeline. Built as the language prerequisite for data science, machine learning and AI engineering work.
Read the companion articles: https://shikharkumar13.github.io/Python-Programming-Code/index.html
- What this is
- Getting started
- Curriculum
- Repository layout
- Reproducible outputs
- Authoring tools
- Where to go next
20 Jupyter notebooks, 1,626 cells, 882 of them executable, with every output committed and verified. Chapters 1 to 10 also have a long-form written article published as a static site.
The material is designed around three principles:
Nothing is asserted without being demonstrated. Where a chapter warns you about
something, a cell shows it happening. The regex that silently matches a commented-out
HTML element, the assert that vanishes under python -O, the @contextmanager
whose cleanup never runs, the price parser that returns None and explodes three
frames later: each is executed, not described.
Every chapter is unlocked by the one before it. Decorators open on the timer written by hand in chapter 7. Generators open on the file read line by line in chapter 10. The capstone in chapter 20 uses essentially all nineteen.
The examples are real. Branded, concrete scenarios rather than foo and bar,
and from chapter 17 onward, real HTTP requests against a live API.
Anyone who wants a solid Python foundation before moving into data work. Chapters 1 to 10 assume no programming background. Chapters 11 to 20 assume you have finished them.
Python 3.10 or newer, and Jupyter. Chapters 1 to 16 use the standard library only; chapters 17 and 18 add two packages, and chapter 19 introduces two development tools.
git clone https://github.com/shikharkumar13/Python-Programming-Code.git
cd Python-Programming-Code
python3 -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt # only needed from chapter 17
pip install jupyterlab
jupyter lab "1. Introduction to Python.ipynb"Chapters 1 to 16 need nothing installed beyond Jupyter itself. If you would rather read than run, chapters 1 to 10 are published as articles at the link above.
| Package | Needed by | Why |
|---|---|---|
requests |
17, 18 | HTTP requests |
beautifulsoup4 |
18 | HTML parsing |
pytest |
19 | Running the tests that chapter writes |
mypy |
19 | Checking the type hints that chapter writes |
Installing them is itself the worked example in chapter 11, which covers virtual
environments and requirements.txt before anything depends on them.
From literals to file I/O. No third-party packages, no installation.
| # | Chapter | Cells | Notebook | Article |
|---|---|---|---|---|
| 1 | Introduction to Python Literals, variables, naming, memory model, interpreted vs compiled |
64 | open | read |
| 2 | Lists, Tuples and Strings Sequence types, slicing, mutability, string methods, formatting |
171 | open | read |
| 3 | Sets and Dictionaries Hashing, set algebra, dictionary methods, comprehensions |
73 | open | read |
| 4 | Operators Arithmetic, comparison, logical, bitwise, identity, precedence |
100 | open | read |
| 5 | Conditional Statements and Loopsif/elif/else, for, while, break, continue, nesting |
102 | open | read |
| 6 | Functions in Python Definition, arguments, defaults, *args, **kwargs, scope, return |
53 | open | read |
| 7 | Types of Functions in Pythonenumerate, zip, map/filter/reduce, lambda, recursion |
54 | open | read |
| 8 | Object-Oriented Programming Classes, four pillars, five inheritance types, MRO, duck typing |
74 | open | read |
| 9 | Exception Handling Hierarchy, try/except/else/finally, chaining, assert, logging |
54 | open | read |
| 10 | File Handling Modes, seek/tell, os, pathlib, CSV, JSON, shutil |
67 | open | read |
The constructs you meet the moment you read real code, and the tooling around them.
| # | Chapter | Cells | Notebook | Article |
|---|---|---|---|---|
| 11 | Modules and Virtual Environmentsimport machinery, writing modules, packages, pip, venv, layout |
81 | open | in progress |
| 12 | Iterators and Generators Iterator protocol, yield, laziness, generator expressions |
105 | open | in progress |
| 13 | Closures and Decorators First-class functions, closures, @, functools, decorator factories |
93 | open | in progress |
| 14 | Context Managers__enter__/__exit__, @contextmanager, suppress, ExitStack |
92 | open | in progress |
| 15 | The Standard Library Toolkitcollections, itertools, functools, datetime |
125 | open | in progress |
| 16 | Regular Expressions Raw strings, character classes, groups, greedy vs lazy, re.escape |
91 | open | in progress |
Getting data from the network, and shipping code that survives contact with it.
| # | Chapter | Cells | Notebook | Article |
|---|---|---|---|---|
| 17 | Working with APIs HTTP verbs, status codes, timeouts, retries, keys, pagination |
64 | open | in progress |
| 18 | Web Scrapingrobots.txt, BeautifulSoup, selectors, tables, encoding, ethics |
61 | open | in progress |
| 19 | Writing Reliable Code Type hints, mypy, docstrings, logging, pytest, tracebacks |
58 | open | in progress |
| 20 | Capstone Project End-to-end pipeline: package, tests, validation, CSV and JSON output |
44 | open | in progress |
.
├── 1. Introduction to Python.ipynb the 20 chapters, in order
├── ...
├── 20. Capstone Project.ipynb
│
├── docs/ the published site (GitHub Pages)
│ ├── index.html series index
│ └── N_topic.html one self-contained article per chapter
│
├── sample_data/ frozen fixtures, committed on purpose
│ ├── github_repo.json real API responses, trimmed (ch. 17)
│ ├── issues_page_*.json paginated responses (ch. 17)
│ └── shop_page_*.html hand-written pages to parse (ch. 18)
│
├── tools/ authoring helpers, not a build step
│ ├── nb_edit.py byte-identical notebook round-trip
│ ├── series.py the canonical chapter list and nav
│ ├── verify_outputs.py re-execute and diff committed outputs
│ └── highlight.py Pygments spans for article code blocks
│
└── requirements.txt
Each article in docs/ is a single self-contained HTML file: inline stylesheet, inline
SVG icon sprite, inline script, and code blocks pre-highlighted with Pygments. The only
external dependency is Google Fonts. Nothing is generated from the notebooks; the
articles are hand-written expansions of the same material.
Notebook outputs are committed, which means a wrong one reaches a reader looking exactly like a right one. Every committed output in this repository has been executed and checked:
python3 tools/verify_outputs.py --all # re-run all 20, diff every output
python3 tools/verify_outputs.py "4. Operators.ipynb"The script executes each notebook in a fresh kernel and compares the result against what is on disk. It reports mismatches without touching the file. All 20 chapters pass from a clean checkout and pass again on a repeat run, which is the check that catches the outputs that are only correct the second time you run them.
Run it twice. Python randomises string hashing per process, so anything printing a
set's iteration order passes one run and fails the next. The same applies to id(),
memory addresses in a default repr, and timings. None of them belong in a committed
output, and two runs is what finds them.
49 cells carry a skip-verify tag because their output legitimately differs every
run: live network calls, timestamps, memory addresses, interactive input(), and set
iteration order. They still execute; only the comparison is skipped, and the reason is
recorded per cell.
The network chapters read committed fixtures from sample_data/, so chapters 17 and 18
produce the same output every time and work with no internet. A small number of clearly
marked cells make a real request, and the notebooks say so up front.
tools/ holds four helpers used to write and maintain the material. They are not a build
step: docs/ is hand-authored and nothing in it is generated from the notebooks.
| Tool | Purpose |
|---|---|
nb_edit.py |
Loads and saves notebooks byte-identically (indent=1, ensure_ascii=False), so a two-line change produces a two-line diff instead of rewriting every line of the file. |
series.py |
The single ordered list of chapters. Regenerates the prev/next navigation across every article, and skips chapters whose article does not exist yet so no page ever links to a 404. |
verify_outputs.py |
Executes a notebook in a fresh kernel and reports outputs that no longer reproduce. |
highlight.py |
Emits the Pygments token spans that the article code blocks require. |
python3 tools/series.py list # chapter list, and what exists so far
python3 tools/series.py nav --check # report prev/next drift across articles
python3 tools/series.py nav # rewrite the nav blocksThis repository ends where the data work begins. Chapter 20 produces a clean, tidy CSV and hands it over deliberately:
- This repository. The Python language, and getting data in.
- NumPy, pandas and exploratory analysis. The dataset from chapter 20 is the file you walk in with.
- Machine learning, MLOps and AI engineering. Everything that needs a trained model or a deployed service.
- Chapters are self-contained enough to read out of order, but each one builds on the vocabulary of the last, and later chapters reference earlier ones by number.
- The demo directories that chapters write while running (
file_handling_demo/,module_demo/,api_demo/and others) are gitignored.sample_data/is the exception and is committed on purpose. - Articles for chapters 11 to 20 are in progress. The notebooks are complete.