Home
What this is¶
One folder per idea. Each holds a page that makes a claim and an examples/ program that proves it. The programs import nothing but the standard library, so any page runs with the python3 you already have — and CI runs every one of them on both Ubuntu and macOS, comparing the output against a recorded answer key. A page cannot quietly go stale, because the build fails when its program stops printing what the page says it prints.
It begins with text and bytes rather than with syntax. That is where a wrong mental model survives longest before failing, and where it fails on someone else's data rather than yours — and it is the part of Python that differs most sharply from C, ABAP and Rust, which makes it the best place to start cross-referencing the sibling libraries.
Start¶
- Start here — what this is, and a four-question diagnostic
- Chapter 1 — Text and bytes — the type boundary, encoding, counting, sorting
- Chapter 2 — Projects and environments — the project file, and the interpreter that runs it
- Katas — the practice track: predict the answer, then run it. The first four are on
bytes - The crosswalk — the same ideas in Rust, C and ABAP, one table per question
- Roadmap — what is written, what is a stub, what is next
- What to write next — the questions backlog, ranked, and the five pages worth writing first
The written lessons¶
| Lesson | The question |
|---|---|
str is not bytes |
Which type am I holding, and why won't Python mix them? |
| String literals | What do the r, b and f prefixes change — and why is '\d' two characters? |
| Encode and decode | Which direction is which, and what does errors= throw away? |
Making a bytes object |
Why is bytes(5) five zero bytes and bytes([5]) one? |
bytearray is the mutable one |
Which of the two binary types can I write into, and what does mutability cost? |
| Counting characters | How long is this string — and which of the four answers did you want? |
| Slicing is not indexing | Why does s[100] raise when s[:100] does not — and what does s[::-1] do to an accent? |
| Is it a letter? | What do isalpha, isdigit and the other ten actually test? |
| Lowercasing is not folding | Why do 'straße' and 'STRASSE' still differ after .lower() — and what is casefold() for? |
repr is not str |
Why is a space "printable" and a tab not — and what did str(b'x') just do? |
| What ends a line | Which characters count as a line break — and why do I get three different answers? |
strip is a set, not a prefix |
Why did lstrip('Arthur: ') eat three more characters than I asked for? |
| Four ways to find it | Why did a search that found nothing pass an if — and which of the four should I have used? |
translate is a table, keyed by ordinal |
Why does maketrans exist, and why is the table keyed by an integer? |
| The format mini-language | Is f'{x:>8}' the same grammar as '{:>8}'.format(x) — and where does % fit? |
| Padding is not alignment | Why is my column still ragged after ljust(20) — and why did zfill keep the minus sign? |
| Sorting is not comparing | Why does sorted() put Łukasiewicz after Zawadzki? |
| Filenames are not text | What is actually allowed in a filename, and why can't I print one? |
| What kind of file is this? | Which of the five APIs answers the question I actually asked — and why did the stdlib stop answering one of them? |
| The codecs registry | What is in the registry that .encode() cannot reach — and why does decoding a stream in chunks break? |
bin() is not the bits |
Why is bin(-9) '-0b1001' and not eight bits — and how do I get the bits? |
pyproject.toml |
What is this file, who reads which part, and how do I read it myself? |
-c is not the prompt |
Why did python3 -c 'chr(0x20AC)' print nothing — and why did the same line without quotes never reach Python? |
Run it¶
python3 01_Text_and_Bytes/sorting_is_not_comparing/examples/sorting_is_not_comparing_py.py
python3 tools/run_examples.py --check # what CI runs
python3 tools/check_katas.py # every kata folded, run and indexed
Sibling libraries¶
This is one of a set. Where another already teaches something, this one links rather than repeats — see the crosswalk.
- Encodings ↗ — bits, bytes, characters, encodings, strings
- Rust ↗ — including
String,&strandchar - ABAP ↗ — the SAP side
House conventions for adding a page: CONTRIBUTING.md.