· 3 min read

Master Advanced Python: 97 Flashcards on Decorators, Descriptors, Lambdas and Exceptions

Master advanced Python with 97 flashcards: metaclasses, descriptors, MRO, decorators, lambdas and exceptions, plus three buggy snippets you should fix first.

Python snake coiled around nested gift boxes and a glowing shield with floating flashcards

Studying. But it's also a video game. 🎮

Flashcards, quizzes and games that make you actually remember.

Start playing — it's free

Posted by

The title promises decorators, lambdas and exceptions — but the first half of Python: Advanced (code TQ3214, 97 cards) is actually Python's object model: metaclasses, descriptors, MRO and nearly every dunder method. That's good news if you're preparing for a senior interview, as long as you study it in the right order.

Study this deck: Python: Advanced (Decorators, Lambda & Exceptions)

1 / 10
Question

Metaclass in Python

Knew itLearning

Tap the card for the answer · swipe right if you knew it, left if not

The real map of the deck

  • Cards 1-49 — object model: metaclasses, __new__ vs __init__, descriptors (data vs non-data), the attribute lookup order, MRO and C3 linearization, super(), __call__, __getattr__ vs __getattribute__, __slots__, __str__ vs __repr__, rich comparisons, __hash__, __bool__, reflected operators (__radd__), container protocol (__getitem__, __contains__, __iter__/__next__, __missing__), __index__, __init_subclass__, __class_getitem__, weakref, async protocols (__await__, __aenter__, __aiter__).
  • Cards 50-59, 74-79, 89-93 — decorators and lambdas: wrappers, @ desugaring, stacking order, @staticmethod/@classmethod, functools.wraps, decorators with arguments, @property setters, lru_cache, class-based decorators, closures, map/filter/sorted(key=…).
  • Cards 60-73, 80-88, 94-97 — exceptions: try/except/else/finally, bare except: vs except Exception, raise … from, the BaseException tree, custom exceptions, assert and -O, EAFP vs LBYL, contextlib.suppress, @contextmanager, ExceptionGroup and except*, traceback.

Sample cards

FrontBack
Data vs non-data descriptorsData (__set__/__delete__) beat the instance __dict__; non-data (__get__ only) lose to it
How does super() work?Delegates to the next class in the MRO, not just the direct parent
__setattr__self.x = y inside it recurses forever — use object.__setattr__
Can you stack multiple decorators?Yes; they apply bottom to top
Write a decorator that takes argumentsThree levels: repeat(n) → decorator(func) → wrapper
except: vs except Exception:Bare except also swallows SystemExit and KeyboardInterrupt
Raise from another exceptionraise NewError(...) from original keeps the chain
ExceptionGroup (3.11+)Multiple exceptions at once, caught with except*

Study tips specific to this deck

Start at card 50, then go back. Decorators and exceptions are what you use daily; the object-model block makes far more sense afterward — a class-based decorator (card 92) is just __call__ (card 9), and @property (card 89) is just a descriptor (card 41). Tag those pairs so they come up together.

Run the snippets — three of them have traps:

  • Card 63's finally example opens the file inside try: if open() fails, f.close() raises NameError. Open before try, or use with.
  • Card 51's wrapper erases __name__ and __doc__; card 74 (functools.wraps) is its fix — merge them.
  • Card 92's CountCalls breaks on methods (no __get__, so no self) and drops **kwargs.

Fix these cards

  • Card 58 says lambdas "can't contain assignments", and card 77 shows a walrus inside a lambda. Rewrite 58 as "no assignment statements".
  • Card 40 returns an OrderedDict from __prepare__: the class namespace has been an ordered dict since 3.6, so the example is outdated.
  • Card 19 omits the classic gotcha: defining __eq__ sets __hash__ to None, making instances unhashable.
  • Card 87: since 3.11, sys.exception() is the simpler way to get the current exception.
  • Duplicates to suspend: 31/48 (__del__), 68/80 (exception hierarchy), 41/89 (property).

For the foundations underneath this deck, see Python Data Structures and Comprehensions.

Look up TQ3214 – Python: Advanced (Decorators, Lambda & Exceptions) in the library on Flip It.

Ready to learn faster? 🚀

Join FLIP IT for free and turn studying into a game.

Create my free account