🌍 Python Programming · flashcards

Python Programming Object-Oriented Programming In Python Flashcards

51 question-and-answer cards covering Object-Oriented Programming In Python 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.

51Cards in deck
24Free preview
~142Chars per answer
FreePrice

24 sample cards from the Object-Oriented Programming In Python deck

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

  1. What is duck typing in Python and how does it relate to polymorphism?

    Duck typing judges suitability by behavior/methods rather than type ('if it walks and quacks like a duck...'). It enables polymorphism without shared inheritance.

  2. What is operator overloading in Python and how is it implemented?

    Operator overloading customizes operators for objects by defining dunder methods, e.g., __add__ for +, __eq__ for ==, __lt__ for <.

  3. What is abstraction in object-oriented programming?

    Abstraction hides complex implementation details and exposes only essential features/interfaces, letting users interact with what an object does, not how.

  4. How do you create an abstract base class in Python?

    Inherit from ABC (from the abc module) or set metaclass=ABCMeta, and decorate methods with @abstractmethod.

  5. What happens if you try to instantiate a class that has an unimplemented @abstractmethod?

    Python raises a TypeError; the class cannot be instantiated until all abstract methods are overridden in a concrete subclass.

  6. What is the purpose of the @abstractmethod decorator from the abc module?

    It marks a method as abstract, forcing subclasses to override it before they can be instantiated, defining a required interface.

  7. What are magic (dunder) methods in Python?

    Special methods with double underscores before and after their name (e.g., __init__, __str__) that Python calls implicitly to support built-in operations and syntax.

  8. What is the difference between __str__ and __repr__ in Python?

    __str__ gives a readable, user-facing string (used by print/str); __repr__ gives an unambiguous, developer-facing representation (used in the REPL/repr), ideally reconstructable.

  9. Which dunder methods implement the comparison operators == and < in Python?

    __eq__ implements ==, and __lt__ implements <. Others include __ne__ (!=), __gt__ (>), __le__ (<=), __ge__ (>=).

  10. What dunder method makes an object callable like a function, and how is it invoked?

    __call__. Defining it lets you write instance(args), which invokes obj.__call__(args).

  11. Which dunder methods enable indexing/subscripting like obj[key] for getting and setting?

    __getitem__(self, key) for obj[key], __setitem__(self, key, value) for obj[key]=value, and __delitem__ for del obj[key].

  12. What dunder method controls the result of len(obj) in Python?

    __len__(self), which must return a non-negative integer.

  13. Which two dunder methods implement Python's context manager protocol (the with statement)?

    __enter__ (runs on entering the with block, returns the resource) and __exit__ (runs on exit, handles cleanup/exceptions).

  14. What dunder method must an object define to be usable in a 'for' loop, and what does it return?

    __iter__, which returns an iterator object (an object with a __next__ method).

  15. What is the purpose of __hash__ and how does it relate to __eq__?

    __hash__ returns an int so the object can be used in sets/dict keys. If you define __eq__, you should keep __hash__ consistent (equal objects must hash equal); defining __eq__ without __hash__ makes instances unhashable.

  16. What is a Python dataclass and how do you create one?

    A dataclass (from the dataclasses module) auto-generates boilerplate like __init__, __repr__, and __eq__ from class-level annotated fields. You apply the @dataclass decorator above the class.

  17. Which dunder methods does @dataclass generate by default?

    By default it generates __init__, __repr__, and __eq__ (eq=True). __hash__ and ordering methods are generated only with specific options (e.g., frozen=True, order=True).

  18. How do you make a Python dataclass immutable?

    Use @dataclass(frozen=True), which makes instances immutable (assigning to fields raises FrozenInstanceError) and makes them hashable by default.

  19. How do you provide a default value for a mutable type (like a list) in a dataclass field?

    Use field(default_factory=list) from the dataclasses module; using a bare mutable default like [] raises a ValueError to avoid shared-state bugs.

  20. What is a namedtuple in Python and what advantage does it offer over a regular tuple?

    A namedtuple (from collections) creates an immutable, tuple-like class whose fields are accessible by name as well as index, improving readability while staying lightweight.

  21. What is the difference between collections.namedtuple and typing.NamedTuple?

    Both create named, immutable tuple types; typing.NamedTuple uses a class syntax with type annotations (and supports methods/defaults more naturally), while collections.namedtuple uses a factory function with a field-name string/list.

  22. What does the type() function return when called with a single object argument, e.g., type(obj)?

    It returns the object's class (its type), e.g., type(5) returns <class 'int'>.

  23. What is the difference between isinstance() and type() == for checking an object's type?

    isinstance(obj, Cls) returns True for instances of Cls or its subclasses (respects inheritance); type(obj) == Cls is True only for the exact class, ignoring subclasses.

  24. Which built-in introspection functions let you inspect, get, set, and check an object's attributes by name at runtime?

    dir() lists attributes; getattr(obj, 'x') retrieves; setattr(obj, 'x', val) sets; hasattr(obj, 'x') checks existence; and obj.__dict__ shows instance attributes.

What this deck covers

This deck covers the Object-Oriented Programming In Python portion of the Python Programming syllabus in question-and-answer form. Browse the full Python Programming syllabus to see how it fits with the rest.

Answers are written to be recallable, not just readable — averaging about 142 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 In Python flashcards FAQ

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

51 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 51-card deck is free inside the Examius app.

What do the Object-Oriented Programming In Python cards cover?

They follow the Object-Oriented Programming In Python portion of the Python Programming syllabus, in question-and-answer form.

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.