Python keywords
All 35 keywords and 4 soft keywords, grouped by statement: every syntax form (including the else clauses on loops and try), what it evaluates to, and the traps. LIVE entries have an in-browser demo with one tab per form.
Also keywords, documented with the operators: and, or, not, in, is.
Branching and looping — including the else clauses on loops that most tutorials skip.
LIVE
break
break
Leave the innermost for or while loop immediately — skipping the rest of the body, the remaining items, and the loop’s else.
LIVEcontinue
continue
Skip the rest of the current loop iteration and go straight to the next one.
LIVEfor
for target in iterable:
Loop over the items of any iterable — lists, strings, dicts, files, generators — one at a time.
LIVEif
if condition:
Run a block only when a condition is truthy — with elif for more tests, else for the fallback, and x if c else y as an expression.
LIVEmatch
match subject:
Structural pattern matching (3.10+): compare a value against patterns — literals, sequences, mappings, classes — and bind the parts you need.
LIVEpass
pass
The statement that does nothing — a placeholder where Python’s grammar needs a statement but you have no code yet.
LIVEwhile
while condition:
Repeat a block for as long as a condition stays truthy — including while True loops that exit with break.