Quiz de Python: Tricky Python Questions

This hard Python quiz is full of snippets that look simple but behave in surprising ways. It covers equal dict keys, operator precedence, nan, empty iterables, class scope and other traps interviewers love to ask about.

Difícil 10 perguntas ~8 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?

d = {True: "a", 1: "b", 1.0: "c"}
print(d)
Mostrar a resposta

C. {True: 'c'} True == 1 == 1.0 and they have the same hash, so all three are the same key. The first key object (True) is kept, while each later assignment replaces the value, ending with 'c'.

O que este quiz cobre

  • Dict keys that are equal, like True, 1 and 1.0
  • Operator precedence with ** and unary minus
  • When a generator expression reads its names
  • nan, all([]) and other edge cases
  • Changing a dict while looping over it, and class body scope

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.