Python interview questions
The Python questions interviewers ask most, with short answers you can explain in your own words. Tap a question to see the answer.
01List vs tuple?+
Lists are mutable, tuples are immutable. Tuples can be dictionary keys and are slightly faster.
02What is a dictionary and how is it implemented?+
A key to value mapping built on a hash table, so lookups are O(1) on average. Keys must be hashable.
03What is the difference between == and is?+
== compares values. is checks if two names point to the same object. Use is only for None.
04What are *args and **kwargs?+
*args collects extra positional arguments into a tuple, **kwargs collects extra keyword arguments into a dict.
05What is a list comprehension?+
A short way to build a list from a loop and an optional condition.
squares = [x * x for x in nums if x > 0]06What is a generator?+
A function that uses yield and produces values one at a time, so it uses little memory for large data.
def read_lines(path):
with open(path) as f:
for line in f:
yield line.strip()07Shallow copy vs deep copy?+
A shallow copy copies the outer object but shares nested objects. copy.deepcopy copies everything.
08What is a decorator?+
A function that wraps another function to add behaviour, like logging or retries, without changing its code.
09How do you handle errors?+
With try, except, else and finally. Catch specific exceptions, not a bare except.
10What does with do?+
It uses a context manager that sets up and cleans up a resource, like closing a file even if an error happens.
11What is the GIL?+
The Global Interpreter Lock lets only one thread run Python bytecode at a time. For CPU work use multiprocessing; threads still help for I/O.
12Mutable default argument problem?+
Defaults are created once, so def f(x=[]) shares the same list between calls. Use None and create the list inside.
13What is a virtual environment?+
An isolated folder with its own Python packages, so projects do not conflict. Create one with python -m venv .venv.
14pandas: loc vs iloc?+
loc selects by labels, iloc selects by integer position.
15How do you handle missing values in pandas?+
Find them with isna(), then dropna() or fillna() depending on the business rule.
16merge vs concat in pandas?+
merge joins DataFrames on keys like SQL. concat stacks them vertically or side by side.
17How do you read a very large CSV?+
Use chunksize to process it in parts, select only needed columns with usecols, and set dtypes.
for chunk in pd.read_csv('big.csv', chunksize=100_000, usecols=['id', 'amount']):
process(chunk)18How do you call a REST API in Python?+
Use requests with a timeout, check the status and parse JSON. Handle pagination and retries.
r = requests.get(url, timeout=30)
r.raise_for_status()
data = r.json()19How do you test Python code?+
With pytest: small test functions with assert, fixtures for setup, and tests run in CI on every change.
20What makes Python code production ready?+
Clear functions, type hints, logging instead of print, config from environment variables, tests, and error handling with retries.
More Python interview questions
Free PDF downloads and premium packs with scenario questions and detailed model answers.
Coming soon
The premium Python interview pack is being prepared.
🎤 Practise with a real mock interview
60 minutes live with Hikmat Ullah, plus written feedback. 30 USD, or 3 for 80 USD.
Python Developer
Python for data work: pandas, APIs, automation, testing and real ETL.
Learn it 1:1 → PROJECTSPython Developer projects
A free starter project, plus Small, Large and Enterprise projects.
See projects → MOREOther subjects
Free interview questions for all 12 subjects.
All interview questions →