Quiz de 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.

Médio 10 perguntas ~6 minutos Aprovação com 80% Python 3.12

Escolha um modo

Jogando como visitante: entre para guardar seu XP e sua sequência.

Pergunta de exemplo

Pergunta 1 de 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)
Mostrar a resposta

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.

O que este quiz cobre

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

Perguntas frequentes

Preciso de uma conta?

Não. Qualquer pessoa pode jogar. Entre para guardar seu XP, sequência, badges e histórico.

Qual versão do Python?

Python 3.12. Toda pergunta sobre a saída foi conferida rodando o código.

Posso refazer?

Pode. Sua melhor nota fica salva, e as perguntas e respostas são embaralhadas a cada vez.