🌍 Python Programming · flashcards

Python Programming Object-Oriented Programming Flashcards

50 question-and-answer cards covering Object-Oriented Programming as it is examined in Python Programming. 24 of them are printed below, taken from across the deck — no signup, no paywall on the preview.

50Cards in deck
24Free preview
18Syllabus topics
~159Chars per answer
FreePrice

24 sample cards from the Object-Oriented Programming deck

Sampled from the end of the deck, so these are different cards from the ones shown on the syllabus page.

  1. What is operator overloading, and which method implements the `+` operator?

    Operator overloading defines how operators behave for your objects via dunder methods. `a + b` calls `a.__add__(b)` (with `b.__radd__(a)` as fallback).

  2. Match these operators to their dunder methods: `-`, `*`, `==`, `<`.

    `-` → `__sub__`, `*` → `__mul__`, `==` → `__eq__`, `<` → `__lt__`.

  3. What does the `__eq__` method define, and what is its default behavior if undefined?

    `__eq__` defines behavior for `==`. Without it, equality defaults to identity comparison (`is`), i.e., objects are equal only if they are the same object.

  4. What happens to `__hash__` when you define `__eq__` on a class, and why does it matter?

    Defining `__eq__` sets `__hash__` to `None`, making instances unhashable (unusable as dict keys or set members). You must define `__hash__` explicitly to restore hashability.

  5. What contract must equal objects satisfy regarding hashing?

    If `a == b` then `hash(a) == hash(b)`. Objects that compare equal must have equal hashes; otherwise they break dict/set behavior.

  6. What does the `functools.total_ordering` decorator provide?

    Given `__eq__` plus one of `__lt__`, `__le__`, `__gt__`, or `__ge__`, `total_ordering` fills in the remaining rich comparison methods automatically.

  7. What is a class method, how is it declared, and what is its first parameter?

    A class method is declared with `@classmethod`; its first parameter is `cls` (the class, not the instance). It is often used for alternative constructors, e.g., `cls(...)`.

  8. What is a static method, how is it declared, and what special parameters does it receive?

    A static method is declared with `@staticmethod`; it receives neither `self` nor `cls`. It is a plain function grouped in the class namespace for organizational purposes.

  9. Compare instance method, class method, and static method by their implicit first argument.

    Instance method → receives `self` (the instance); class method → receives `cls` (the class); static method → receives no implicit argument.

  10. Why is `@classmethod` preferred over hardcoding the class name in an alternative constructor?

    Using `cls(...)` respects inheritance: a subclass calling the alternative constructor gets an instance of the subclass, whereas hardcoding the base class name would not.

  11. What is an Abstract Base Class (ABC), and which module provides the tooling?

    An ABC defines an interface that cannot be instantiated directly and requires subclasses to implement certain methods. The `abc` module provides `ABC`/`ABCMeta` and `@abstractmethod`.

  12. How do you declare an abstract method, and what happens if a subclass doesn't implement it?

    Decorate it with `@abstractmethod`. If a concrete subclass fails to override all abstract methods, attempting to instantiate it raises `TypeError`.

  13. What is the standard way to make a class abstract using the `abc` module?

    Inherit from `abc.ABC` (or set `metaclass=abc.ABCMeta`) and mark required methods with `@abstractmethod`. Instantiating the class directly then raises `TypeError`.

  14. What does the `@dataclass` decorator generate automatically?

    From `dataclasses`, `@dataclass` auto-generates `__init__`, `__repr__`, and `__eq__` (and optionally ordering and `__hash__`) based on class-level annotated fields.

  15. In a dataclass, why must mutable default values use `field(default_factory=...)`?

    A bare mutable default (e.g., `x: list = []`) would be shared across instances and raises a ValueError in dataclasses. `field(default_factory=list)` creates a fresh object per instance.

  16. What does `@dataclass(frozen=True)` do?

    It makes instances immutable: attribute assignment after creation raises `FrozenInstanceError`. Frozen dataclasses also become hashable, so they can be used in sets/dict keys.

  17. What does the `order=True` parameter add to a dataclass?

    It generates the comparison methods `__lt__`, `__le__`, `__gt__`, and `__ge__`, which compare instances field-by-field as a tuple of their values.

  18. What is the purpose of `__slots__` in a class?

    `__slots__` declares a fixed set of allowed attributes, preventing creation of a per-instance `__dict__`. This reduces memory usage and can speed up attribute access.

  19. Name two consequences of defining `__slots__` on a class.

    (1) You cannot add attributes not listed in `__slots__` (raises AttributeError); (2) instances have no `__dict__` by default, so dynamic attributes and (unless declared) `__weakref__` are unavailable.

  20. When does `__slots__` give the biggest memory benefit?

    When you create very large numbers of small, fixed-shape instances—eliminating the per-instance `__dict__` saves significant memory across many objects.

  21. What is the difference between `__str__` fallback and `__repr__` in a container like a list?

    When you print a list, its elements are shown using their `__repr__`, not `__str__`. So a list of objects displays each element's `repr` regardless of `__str__`.

  22. Which dunder methods implement the six rich comparisons?

    `__lt__` (<), `__le__` (<=), `__gt__` (>), `__ge__` (>=), `__eq__` (==), and `__ne__` (!=).

  23. What is the difference between `isinstance()` and `type() ==` for type checking, especially with inheritance?

    `isinstance(obj, Cls)` is True for instances of `Cls` or any subclass, respecting inheritance; `type(obj) == Cls` is True only for the exact class, ignoring subclasses. `isinstance` is generally preferred.

  24. In multiple inheritance, when a diamond hierarchy exists (D inherits B and C, both inheriting A), why does cooperative `super()` matter?

    C3 linearization ensures A is visited only once (after both B and C). Using `super().__init__()` in each class lets the MRO chain each initializer exactly once, avoiding duplicate or skipped base initialization.

What this deck covers

The Object-Oriented Programming deck follows the Python Programming Object-Oriented Programming syllabus — 5 chapters and 18 topics — so questions land on material that is genuinely examinable rather than trivia around it. That works out to roughly 10.0 cards per chapter.

Answers are written to be recallable, not just readable — averaging about 159 characters, which is long enough to carry the reasoning and short enough to say out loud.

A deck like this earns its keep on the second and third pass. Read the syllabus first so you know the shape of the subject, then use the cards to find the specific facts that have not stuck.

Object-Oriented Programming flashcards FAQ

How many Object-Oriented Programming flashcards are in this Python Programming deck?

50 cards. This page previews 24 of them, sampled evenly across the deck so you can judge the difficulty before installing anything.

Are these Python Programming flashcards free?

Yes. The preview here is free to read with no signup, and the full 50-card deck is free inside the Examius app.

What do the Object-Oriented Programming cards cover?

They follow the Python Programming Object-Oriented Programming syllabus — 5 chapters and 18 topics — so the questions track what is actually examinable.

How should I use these flashcards?

Read the syllabus first so you know the shape of the subject, then drill the deck. Examius schedules each card with spaced repetition, so cards you keep missing come back sooner and ones you know drift further apart.