Quiz Python: Output-Based Python Questions

Many Python interviews hand you a snippet and ask "what does this print?". This quiz is ten of those, each mixing two ideas such as rebinding vs mutation, slicing with steps, sort keys or exhausted generators.

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?

a = [1]
b = a
a = a + [2]
c = [1]
d = c
c += [2]
print(b, d)
Mostra la risposta

A. [1] [1, 2] a + [2] builds a new list and rebinds a, so b still points to the old [1]. c += [2] extends the list in place, and d is that same list, so it shows [1, 2].

Cosa copre questo quiz

  • a = a + [x] vs a += [x]
  • Slicing with steps and negative steps
  • Dict comprehensions with repeated keys
  • Sort keys that use tuples
  • Generators that can only be used once

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.