Python interview questions and answers
Python interviews test core language features, data structures and a framework like Django, Flask or FastAPI. Keep a small project ready to discuss.
12 questions. Read each one, start the timer and answer out loud as if you were in the room, then open the tip. Nothing is recorded.
What is the difference between a list, tuple, set and dict?
What a good answer covers
List: ordered and changeable. Tuple: ordered and fixed. Set: unique items, unordered. Dict: key-value pairs.
What are mutable and immutable types?
What a good answer covers
Mutable objects can change in place, like lists and dicts. Immutable ones cannot, like ints, strings and tuples.
What is a decorator?
What a good answer covers
A function that wraps another to add behaviour, like logging or login checks, using @ syntax.
What are generators and yield?
What a good answer covers
Functions that yield values one at a time, so large sequences don’t need to fit in memory.
Explain *args and **kwargs.
What a good answer covers
*args collects extra positional arguments into a tuple; **kwargs collects extra keyword arguments into a dict.
What is the GIL?
What a good answer covers
CPython’s lock that lets one thread run Python code at a time. Use multiprocessing for CPU-heavy work and asyncio or threads for I/O.
What is the difference between a shallow and a deep copy?
What a good answer covers
A shallow copy copies the outer object but shares inner ones. A deep copy copies everything.
How do you manage packages and environments?
What a good answer covers
A virtual environment per project with venv, pip and a requirements file, or a tool like Poetry.
Write a list comprehension that keeps even squares.
What a good answer covers
[x * x for x in nums if x % 2 == 0]. Explain why it reads better than a loop.
Django, Flask or FastAPI: when would you use each?
What a good answer covers
Django for full apps with admin and ORM, Flask for small flexible apps, FastAPI for fast typed APIs.
How do you handle exceptions?
What a good answer covers
try, except for specific errors, else when nothing failed, finally for cleanup, and custom exceptions for clarity.
How would you read a very large CSV file?
What a good answer covers
Read it line by line with the csv module, or in chunks with pandas, instead of loading it all at once.
All 12 questions with answers
1. What is the difference between a list, tuple, set and dict?
List: ordered and changeable. Tuple: ordered and fixed. Set: unique items, unordered. Dict: key-value pairs.
2. What are mutable and immutable types?
Mutable objects can change in place, like lists and dicts. Immutable ones cannot, like ints, strings and tuples.
3. What is a decorator?
A function that wraps another to add behaviour, like logging or login checks, using @ syntax.
4. What are generators and yield?
Functions that yield values one at a time, so large sequences don’t need to fit in memory.
5. Explain *args and **kwargs.
*args collects extra positional arguments into a tuple; **kwargs collects extra keyword arguments into a dict.
6. What is the GIL?
CPython’s lock that lets one thread run Python code at a time. Use multiprocessing for CPU-heavy work and asyncio or threads for I/O.
7. What is the difference between a shallow and a deep copy?
A shallow copy copies the outer object but shares inner ones. A deep copy copies everything.
8. How do you manage packages and environments?
A virtual environment per project with venv, pip and a requirements file, or a tool like Poetry.
9. Write a list comprehension that keeps even squares.
[x * x for x in nums if x % 2 == 0]. Explain why it reads better than a loop.
10. Django, Flask or FastAPI: when would you use each?
Django for full apps with admin and ORM, Flask for small flexible apps, FastAPI for fast typed APIs.
11. How do you handle exceptions?
try, except for specific errors, else when nothing failed, finally for cleanup, and custom exceptions for clarity.
12. How would you read a very large CSV file?
Read it line by line with the csv module, or in chunks with pandas, instead of loading it all at once.
Before the interview
- Read the job description twice and match two of your examples to what it asks for.
- Keep printed copies of your resume, ID proof and certificates ready, even for online rounds.
- Know your current CTC, expected salary and notice period. Check typical pay in our salary guide, and compare offers with the in-hand salary calculator.
- Genuine employers never ask you to pay for an interview, training kit or joining. Report anyone who does.