Home › Python Output Practice
Python output prediction practice
🔮 36 output questionsFree, no loginInterview-style
How this archive works
Every card is a "predict the output" question — the exact format used in Python interviews and university exams. The featured questions below run right on the page: type your predicted output, check it, and get a line-by-line trace of why. The rest open in PyDebug's interactive editor, which verifies your prediction automatically.
New to the format? Start with the output-prediction strategy guide, then come back and drill.
Filter
Answer on this page
dict.get() vs [key]
A missing key is a KeyError with brackets and None with get(). Plus what len() and pop() report after setdefault adds a key.
dictionaries easyfinally Before return
A finally block runs even when the try block returns — and it runs before the returned value reaches the caller. Two verified traces.
exceptions hardMutable Default Argument
A list default argument is created once, not per call — so the second call sees the first call's items. Verified output plus a…
functions hardPython List Slicing
Predict what three print() calls with list slices output — nums[1:4], nums[-2:], nums[::2]. Type your answer, reveal the result, and read a…
lists easyShared List References
Two names, one list: why changing one row of a built grid changes the other, and why list.copy() still is not enough for nested lists.
lists mediumsort() vs sorted()
sorted() returns a new list once — appending afterwards does not re-sort it. Compare sort() and sorted() before an exam question traps you.
lists mediumWhy append() Returns None
list.append() changes the list and hands back None. Print the result of either line and see why chained 'x = y.append(…)' wipes a…
lists easyfor Loop With range()
A for loop over range(1, 10, 3) with a running total — predict every printed line including the one after the loop. Answer reveal with a…
loops medium// and % With Negatives
Floor division rounds down, not toward zero — which is why -7 // 2 is -4 and -7 % 2 is still 1. The rule that fixes both signs at once.
numbers mediumWhy 0.1 + 0.2 Is Not 0.3
Binary floats cannot hold 0.1 exactly, so 0.1 + 0.2 prints 0.30000000000000004 and round(2.675, 2) goes down. Real output, plus Decimal.
numbers mediumTruthiness and the Ternary
0 is false but '0' is true, empty lists are false, and not/and/or return objects instead of booleans. Verified output with the…
operators mediumHow a Set Deduplicates
1, 1.0 and True are one member, not three — and set order is not insertion order. Verified output with the hash rule behind it.
sets mediumNegative Indexes and Slices
Three slice expressions on 'python' — negative stop, a reversed slice chained with another slice, and why the end index never…
strings easyPython String Multiplication
word * 3, len() of the result, indexing into it, and the '' * 0 edge case — four prints to predict, then a full line-by-line…
strings easyThe One-Element Tuple Comma
Parentheses do not make a tuple — the comma does. See why (1) is an int, (1,) * 2 differs from 1 * 2, and unpacking needs that comma.
tuples easyAnswer in the interactive editor
break vs continue
Interactive — predict in the editor, get checked instantly.
loops mediumLoop variable after the loop ends
Interactive — predict in the editor, get checked instantly.
loops mediumelse clause on a for loop
Interactive — predict in the editor, get checked instantly.
loops mediumenumerate with a start value
Interactive — predict in the editor, get checked instantly.
loops easyList multiplication
Interactive — predict in the editor, get checked instantly.
lists mediumNegative indexing
Interactive — predict in the editor, get checked instantly.
lists easyList copy vs reference
Interactive — predict in the editor, get checked instantly.
lists easySlicing excludes the end index
Interactive — predict in the editor, get checked instantly.
lists easyString repetition and length
Interactive — predict in the editor, get checked instantly.
strings easyString multiplication and indexing
Interactive — predict in the editor, get checked instantly.
strings easyString multiplication in a loop
Interactive — predict in the editor, get checked instantly.
strings mediumDefault parameter values
Interactive — predict in the editor, get checked instantly.
functions mediumFunction returning nothing
Interactive — predict in the editor, get checked instantly.
functions easyChained assignment
Interactive — predict in the editor, get checked instantly.
functions easyMutable default argument trap
Interactive — predict in the editor, get checked instantly.
functions mediumdict.get() with a default
Interactive — predict in the editor, get checked instantly.
dictionaries mediumDictionary keys must be unique
Interactive — predict in the editor, get checked instantly.
dictionaries mediumTuple immutability
Interactive — predict in the editor, get checked instantly.
tuples easySets remove duplicates
Interactive — predict in the editor, get checked instantly.
sets easytry/except/else flow
Interactive — predict in the editor, get checked instantly.
exceptions mediumClass variable shared across instances
Interactive — predict in the editor, get checked instantly.
oop mediumWhy output prediction makes you a better debugger
Debugging is prediction in reverse: you read code that already misbehaved and reconstruct what it must have done. Practising forward prediction — stating exactly what each line prints before running it — builds the same mental interpreter. The learners who get fast at these questions are the same ones who stop needing twenty print statements to find a bug.
Struggling with a specific crash instead? The Python error explainer decodes the six most common exceptions, and the tricks collection catalogues the classic traps.