Python-Quiz: Python OOP Interview Questions

This Python quiz covers the object-oriented questions that come up in most Python interviews. You will trace super() through multiple inheritance, see what name mangling really does, and check your understanding of abstract classes, __slots__ and duck typing.

Mittel 10 Fragen ~6 Minuten Bestanden ab 80% Python 3.12

Modus wählen

Du spielst als Gast: Melde dich an, damit XP und Serie gespeichert werden.

Beispielfrage

Frage 1 von 10

What does this print?

class Basket:
    items = []

    def add(self, item):
        self.items.append(item)

a = Basket()
b = Basket()
a.add("apple")
print(b.items)
Lösung zeigen

B. ['apple'] items is a class attribute, so there is one list shared by every Basket. self.items.append changes that shared list. Create the list in __init__ with self.items = [] to give each object its own.

Darum geht es in diesem Quiz

  • Shared mutable class attributes
  • super() and the MRO in multiple inheritance
  • Name mangling with __name
  • Abstract base classes and __slots__
  • Duck typing and composition

Häufige Fragen

Brauche ich ein Konto?

Nein. Jeder kann spielen. Mit Anmeldung werden XP, Serie, Abzeichen und Verlauf gespeichert.

Welche Python-Version?

Python 3.12. Jede Frage zur Ausgabe wurde geprüft, indem der Code ausgeführt wurde.

Kann ich es wiederholen?

Ja. Dein Bestwert bleibt erhalten, und Fragen und Antworten werden jedes Mal neu gemischt.