โ† All Python Flashcard Decks

Object-Oriented Programming Basics Flashcards

7 cards from real Python 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 Basics flashcards as text
  1. What does the `super()` function do in Python?

    Answer: Calls a method from the parent class

    `super()` returns a proxy object that delegates method calls to a parent class, enabling cooperative multiple inheritance.

  2. Which of the following correctly defines a class method in Python?

    Answer: @classmethod def method(cls):

    Class methods are decorated with `@classmethod` and receive the class itself as the first argument, conventionally named `cls`.

  3. What is the output of `type(42)` in Python?

    Answer:

    `type()` returns the class object of the argument, displayed as `` for integers.

  4. Which magic method is called when an object is created?

    Answer: __init__

    `__init__` is called after the object is created to initialize its attributes; `__new__` allocates it but is rarely overridden.

  5. What does name mangling do in Python (e.g., `__attr`)?

    Answer: Renames the attribute to `_ClassName__attr`

    Python mangles `__attr` to `_ClassName__attr` to reduce accidental override in subclasses, but it is still accessible.

  6. What is an abstract class in Python?

    Answer: A class that cannot be instantiated directly and must be subclassed

    Abstract classes, created with `abc.ABC`, contain abstract methods that subclasses must implement before instantiation.

  7. Which statement about `__str__` and `__repr__` is correct?

    Answer: `__repr__` is for developers; `__str__` is for end users

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