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.
Save with packages
Bundles that include Python. See all packages →
Python Developer Combo
Python Developer, both levels: Intermediate and Advanced.
Data Engineer Track
Everything a data engineering interview covers.
AI Track
For AI engineer and GenAI data roles.
Complete Bundle
All 12 courses, both levels. 24 PDFs.
Questions before you buy
How do I get the PDF?+
Tap "Buy on WhatsApp". After payment I send you a private download link on WhatsApp, and you can download the file straight away.
How long does delivery take?+
Usually within a few hours of payment, and always within 24 hours.
How do I pay?+
I share the payment options on WhatsApp before you pay. Prices are in US dollars, and you can pay in your local currency at the day's rate.
Can I see a sample first?+
Yes. Every premium pack has a free sample with the first 5 questions. Use the "Free sample" button on the pack.
Can I get a refund?+
Because these are digital files, payments are not refundable once the file is sent. If a file does not open or something is missing, message me and I will fix it quickly.
What students say
All reviews →🎤 Practise with a real mock interview
60 minutes live with Hikmat Ullah, plus written feedback. Bronze 20 USD (1 session), Silver 50 USD (3 sessions), Gold 80 USD (5 sessions).
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 →