Quiz Python: 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.

Medio 10 domande ~6 minuti Superato con il 80% Python 3.12

Scegli una modalità

Stai giocando come ospite: accedi per salvare XP e serie.

Domanda di esempio

Domanda 1 di 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)
Mostra la risposta

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.

Cosa copre questo 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

Domande frequenti

Serve un account?

No. Chiunque può giocare. Accedi per salvare XP, serie, badge e cronologia.

Quale versione di Python?

Python 3.12. Ogni domanda sull'output è stata verificata eseguendo il codice.

Posso rifarlo?

Sì. Il tuo miglior punteggio resta salvato, e domande e risposte vengono mescolate ogni volta.