Python interview questions for junior developers (with answers)
The Python questions juniors actually get asked: predicting output, mutable defaults, generators, decorators, the GIL, testing and code review, with short answers and why they matter.
Junior Python interviews rarely ask you to invert a binary tree. They ask whether you understand the language well enough to write correct code in a team. Here are the questions that come up again and again, with short answers. Try answering each out loud before reading ours.
Predict the output
Interviewers love these because they show whether you understand what Python actually does.
1. What does this print?
a = [1, 2]
b = a
a += [3]
print(b)[1, 2, 3]. b = a copies the reference, not the list, and += on a list changes it in place.
2. And this?
def add(item, items=[]):
items.append(item)
return items
add(1)
print(add(2))[1, 2]. The default list is created once and shared by every call. This is the
mutable default argument trap; the fix is
items=None.
3. This one catches almost everyone:
handlers = [lambda: i for i in range(3)]
print([h() for h in handlers])[2, 2, 2]. Closures look up i when they're called, by which time the loop is over.
Core language
4. List vs tuple? Lists are mutable, tuples aren't. Tuples can be dictionary keys and signal
"this is a fixed record", like (lat, lon).
5. Why must dictionary keys be hashable? A dict finds keys by their hash. If a key could change, its hash would change and the dict could never find it again.
6. is vs ==? == compares values, is checks it's the same object. Use is only for
None (and other singletons).
**7. What are *args and **kwargs?** Extra positional arguments as a tuple, extra keyword
arguments as a dict. Common in decorators.
Intermediate
8. What's a generator, and why use one? A function with yield that produces values lazily,
one at a time. It handles data bigger than memory. See
generators and iterators.
9. What does with guarantee? Cleanup runs even if the block raises. See
context managers.
10. When does the else of a try block run? Only if no exception was raised in try. It
keeps the "happy path" out of the protected block.
11. What's the GIL? CPython's global interpreter lock lets one thread run Python bytecode at a time. Threads still help with waiting (network, disk); for CPU-heavy work, use processes.
Practical and professional
12. How do you test code that uses the current time? Pass the time (or a clock function) in, and pass a fixed one in the test. Mocking works too, but injection keeps the code simple.
13. You're given a vague ticket. What do you do first? Restate it in your own words, list the questions and edge cases, and confirm before building. Read working with tickets.
14. A teammate's PR adds except Exception: pass. What do you say? It hides real bugs. Catch
the specific exception you expect, and log or re-raise the rest. See the
code review checklist.
15. How would you find out why something is slow? Measure first (a profiler, timing, query plans), then fix the biggest cost. Often it's an O(n²) loop or a missing database index; see complexity in practice.
Beyond the questions
Most interviews also include a short coding task and a conversation about something you built. The second part decides more offers than people think: be ready to explain one project in depth, including what you'd do differently. If you don't have one yet, the Become a Python Developer career path ends with a 25-question exam in exactly this style, after three projects you can talk about.
Questions and answers
- What Python questions are asked in a junior developer interview?
- Expect core language questions (lists vs tuples, dicts, mutability, scope), predict-the-output snippets, a small coding task, and questions about testing, Git and how you'd approach a vague requirement. Many interviews also ask you to review or debug a short piece of code.
- How should I prepare for a Python technical interview?
- Make sure you can explain the core language out loud, practise reading code you didn't write, build one or two projects you can discuss in depth, and do a handful of timed exercises to get used to the format.
Practise it
Read next
- How to become a Python developer: a realistic roadmap
What a junior Python developer actually does, the skills employers check, the order to learn them in, and how to prove you can do the job without a degree.
- Python's mutable default argument trap (and how to fix it)
Why def f(items=[]) shares one list between every call, how it causes bugs that look impossible, and the None pattern that fixes it, with dataclasses and class attributes too.
- Python generators and iterators, explained with real examples
How iteration works under the hood, how yield turns a function into a lazy generator, how pipelines process files bigger than memory, and the exhaustion trap that catches everyone.
- LeetCode alternatives: how to become job-ready, not just interview-ready
Coding puzzles train one skill. Here's what else the job needs, how to practise it, and how to balance interview prep with real project work.