Python interview questions and answers
Python technical interviews usually start with data types (lists, tuples, dictionaries) and the difference between mutable and immutable objects, then move on to functions, decorators, generators and error handling. For backend roles, the GIL and concurrency come up often too.
These are questions Syntax, the recruiter in SyntaxQuest’s mock interview, may ask you for backend, full-stack and data roles, each with a short, verified answer. After them come three code snippets with classic traps you should be able to explain.
Python technical questions
Short answers, the way you would say them out loud. If you can explain them in your own words and give an example, you’re on the right track.
-
What’s the difference between a list and a tuple?
A list is mutable: you can add, remove or change items. A tuple is immutable, a bit lighter and meant for data that shouldn’t change. A tuple can also be a dictionary key if all its items are hashable; a list never can.
-
What is the GIL (Global Interpreter Lock)?
A CPython lock that lets only one thread execute Python bytecode at a time. That’s why threads don’t speed up CPU-heavy code (use multiprocessing for that), although they do help with I/O such as network or disk, because the GIL is released while they wait. Since Python 3.13 there’s also an optional free-threaded build without the GIL.
-
What is a list comprehension and when should you use it?
A concise way to build a list from another iterable: [x * 2 for x in nums if x > 0]. Use it for simple transformations or filters; if the logic gets complicated, a regular for loop reads better.
-
What’s the difference between == and is?
== compares values; is compares identity, that is, whether both names point to the same object. Two lists with the same items are == but not is. Use is to compare with None (x is None) and, in general, == for everything else.
-
What is a decorator?
A function that takes another function and returns an extended version of it without changing its code. You apply it with @ above the definition. For example, @functools.lru_cache caches results so they aren’t computed again.
-
Why is a list as a default parameter value dangerous?
Because the default value is evaluated only once, when the function is defined, so every call shares the same list. Use None as the default and create the list inside the function.
-
How does a generator differ from a regular function?
A regular function computes everything and hands it back with return. A generator uses yield: it produces values one at a time, on demand, pausing in between, so it never needs the whole sequence in memory. It’s ideal for large or infinite sequences.
-
How does Python handle errors?
With exceptions: try for code that might fail, except to catch specific errors, else for what should run only if nothing failed and finally for what must always run. Catch specific exceptions, like ValueError, instead of a bare except that swallows everything.
-
What are *args and **kwargs?
*args collects extra positional arguments into a tuple and **kwargs collects keyword arguments into a dict. They let you write functions with a flexible signature, such as decorators that forward any argument to the original function.
-
What is a dict comprehension? Give an example.
The same as a list comprehension, but it builds a dictionary from key: value pairs. For example, {w: len(w) for w in words} maps each word to its length.
Code questions: what does it print?
Many interviews show you a short snippet and ask you to predict the result and explain why. Try to answer before opening the solution.
-
A list as a default value
What does this code print?
def add(item, bucket=[]): bucket.append(item) return bucket add(1) print(add(2))Show answer
Output
[1, 2]The default [] is created only once, when the function is defined: the second call gets the same list, which already holds the 1. Fix it with bucket=None and create the list inside.
-
Multiplying a list of lists
What does this code print?
grid = [[0] * 2] * 2 grid[0][0] = 1 print(grid)Show answer
Output
[[1, 0], [1, 0]][[0] * 2] * 2 repeats a reference to the same inner list twice, so changing one row changes both. To create independent rows, use [[0] * 2 for _ in range(2)].
-
Lambdas in a loop
What does this code print?
funcs = [lambda: i for i in range(3)] print([f() for f in funcs])Show answer
Output
[2, 2, 2]The lambdas capture the variable i, not its value: they read it when called, and by then the loop has finished with i = 2. Fix it by binding the value as a default argument: lambda i=i: i.
Practice with a mock interview
Knowing the answer isn’t enough: you have to explain it calmly in front of someone. In SyntaxQuest, Syntax plays the recruiter on a video call, asks you Python questions for the role and your level (junior, mid-level or senior), grades the content of your answers and gives you feedback on your eye contact, pace and filler words. At the end, Syntax tells you whether you’d be hired.
Included in Pro. Nothing is recorded: the camera is analyzed on your iPhone.
Python interview FAQ
What do they ask in a Python technical interview?
The usual topics are data types and mutability, comprehensions, functions (*args, **kwargs, decorators), generators, exceptions and, for backend roles, the GIL and concurrency. There’s almost always a coding exercise or a “what does this print?” question too.
What else comes up in a Python interview for data roles?
Beyond the language, expect pandas and NumPy (filtering, grouping and joining tables), SQL and how to clean incomplete or duplicated data. In SyntaxQuest’s mock interview, the Data role mixes Python and SQL questions.
Python 2 or Python 3?
Python 3. Python 2 reached end of life in January 2020, and companies today work with recent Python 3 releases. If asked about the differences, mention print as a function, division (/ always returns a float and // is floor division) and Unicode strings by default.
How do I prepare for a Python interview?
Review the fundamentals, solve short exercises and, above all, answer out loud: explaining an idea clearly is harder than recognizing it. In SyntaxQuest you can review with the free Python course and do video-call mock interviews with Syntax, included in Pro.
Does the mock interview record my camera?
No. Nothing is recorded: the camera is analyzed on your iPhone to give you feedback on eye contact, and Apple’s speech recognition transcribes your voice. Syntax only gets the text of your answer.