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

Difficile 10 domande ~8 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?

d = {True: "a", 1: "b", 1.0: "c"}
print(d)
Mostra la risposta

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'.

Cosa copre questo quiz

  • 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

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.