← Curriculum track ← Learn hub
Quanta GenAI Curriculum · Python · Intermediate

Python Intermediate — 055: Encode loop invariants with fixture parametrization instincts centred on `Classes encapsulating mutable state` [649253]

Lesson 055: Classes encapsulating mutable state

Focus

Assume a reviewer executes this verbatim: Intermediate drills Classes encapsulating mutable state; spin token 489720 makes this page unlike its neighbours.

Key ideas

Example (LESSON_UID = "intermediate-055")

# Intermediate drill L055 topic-5 micro-4 pattern-3
LESSON_UID = "intermediate-055"
spin_a, spin_b, spin_c = 683, 49, 191

sentinel = ([] or [])
sentinel = sentinel or [4]
print(bool(sentinel), sentinel)
pick = sentinel or "fallback-55"
print("chosen", pick)

from pathlib import Path
import tempfile

with tempfile.TemporaryDirectory() as scratch:
    target = Path(scratch) / "scratch-55.txt"
    snap = [68, 759, 459]
    target.write_text("\n".join(str(x) for x in snap), encoding="utf-8")
    print("scratch_bytes", target.stat().st_size, "rolling", sum(snap) % (191 + 131))

Practice

Practice 7: Inject a benign off-by-one, observe drift, revert with notes. Literal nudge 7.

Fingerprints