← All POC Flashcard Decks

Object-Oriented Programming in Python Flashcards

7 cards from real POC practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.

Read the first 7 Object-Oriented Programming in Python flashcards as text
  1. What is a mixin in Python OOP?

    Answer: A class designed to provide optional methods to other classes via multiple inheritance without standing alone

    Mixins are small, focused classes providing reusable behavior, combined via multiple inheritance without being used independently.

  2. What is the difference between `__repr__` and `__str__`?

    Answer: `__repr__` is for developers (unambiguous), `__str__` is for end-users (readable)

    `__repr__` should return an unambiguous developer-facing string; `__str__` returns a readable user-facing string.

  3. Which of the following demonstrates operator overloading in Python?

    Answer: Defining `__add__` in a class so `+` works on custom objects

    Operator overloading is achieved by implementing dunder methods like `__add__`, `__mul__`, etc., in a class.

  4. What happens when you use `__slots__` in a Python class?

    Answer: It restricts the object to only the listed attributes, saving memory

    `__slots__` prevents creation of a `__dict__` per instance and restricts attribute names, reducing memory usage.

  5. In Python, what is composition (as opposed to inheritance)?

    Answer: Building a class that contains instances of other classes as attributes, rather than inheriting from them

    Composition models a 'has-a' relationship — a class holds references to objects of other classes rather than extending them.

  6. What is the result of defining `__len__` in a class?

    Answer: Allows `len(obj)` to return a meaningful value for instances of the class

    Implementing `__len__` lets built-in `len()` work on custom objects by returning an integer length.

  7. Which statement about Python's `object` base class is correct?

    Answer: All Python 3 classes implicitly inherit from `object`

    In Python 3, every class implicitly inherits from `object`, gaining default implementations of dunder methods like `__str__` and `__eq__`.