Python developer interview questions and answers
Python interviews test the language's core data types, how Python works under the hood and how you write clean, testable code. Here are the questions asked most, with what each checks.
What to revise before the interview
- Data types: list, tuple, set, dict and their complexity
- Mutable vs immutable objects
- Functions: *args, **kwargs, default arguments
- Decorators, generators and iterators
- OOP in Python: classes, inheritance, dunder methods
- Exceptions and context managers (with)
- The GIL, threading vs multiprocessing vs asyncio
- A web framework: Django or Flask/FastAPI
1.What is the difference between a list and a tuple?
- What they're checking
- Core data types and mutability.
- How to answer
- Lists are mutable and suit collections that change; tuples are immutable, slightly lighter and can be dictionary keys if their contents are hashable.
2.How is a dictionary implemented, and what is the time complexity of a lookup?
- What they're checking
- Whether you understand performance, not only syntax.
- How to answer
- A dict is a hash table: keys are hashed to find a slot, so lookups, inserts and deletes are O(1) on average. Keys must be hashable. Since Python 3.7, dicts keep insertion order.
3.What is a decorator? Write a simple one.
- What they're checking
- Comfort with functions as objects.
- How to answer
- A decorator takes a function and returns a new function that adds behaviour around it.
- Example answer
- “A timing decorator: def timed(fn): def wrapper(*args, **kwargs): start = time.time(); result = fn(*args, **kwargs); print(time.time() - start); return result; return wrapper. I'd add functools.wraps to keep the original name.”
4.What is a generator, and why use one?
- What they're checking
- Memory-aware coding.
- How to answer
- A function that uses yield to produce values one at a time instead of building a whole list. Useful for large files or streams, because it keeps memory use low.
5.Explain mutable default arguments - what goes wrong?
- What they're checking
- A classic Python gotcha that shows real experience.
- How to answer
- Default values are created once, when the function is defined. A default list shared across calls keeps growing. Use None as the default and create the list inside the function.
6.What is the GIL, and how does it affect threading?
- What they're checking
- Understanding concurrency in CPython.
- How to answer
- The Global Interpreter Lock lets only one thread run Python bytecode at a time in CPython. Threads still help for I/O-bound work; for CPU-bound work use multiprocessing. asyncio suits many concurrent I/O tasks.
7.What are *args and **kwargs?
- What they're checking
- Function design basics.
- How to answer
- *args collects extra positional arguments into a tuple; **kwargs collects extra keyword arguments into a dict. Common in wrappers and decorators.
8.How do you handle exceptions and clean up resources?
- What they're checking
- Writing robust code.
- How to answer
- Catch specific exceptions, not a bare except. Use with for files and connections so they are closed even on errors; mention finally and raising custom exceptions with clear messages.
9.Django vs Flask (or FastAPI) - when would you use each?
- What they're checking
- Framework judgement for backend roles.
- How to answer
- Django is batteries-included: ORM, admin and auth, good for full applications. Flask and FastAPI are lighter and suit APIs and microservices; FastAPI adds type-based validation and async support.
10.Solve: find the first non-repeating character in a string.
- What they're checking
- Basic problem solving in Python.
- How to answer
- Count characters with collections.Counter, then return the first character whose count is 1. Explain that it's O(n) time.
On a live call, Cuelyte AI hears questions like these and has an answer ready in about a second, built from your resume and notes. Coding interviews: how Cuelyte AI helps
Frequently asked questions
What Python topics are asked in fresher interviews?
Data types, string and list operations, loops, functions, OOP basics and simple coding problems. Knowing list comprehensions and dictionaries well goes a long way.
Do Python developer interviews include coding rounds?
Usually yes - often string, array and dictionary problems in Python, and for backend roles, questions on APIs and databases.
Should I learn Django or Flask for interviews?
Either is fine. Learn one well enough to explain a project you built with it: models, views or routes, and how you connected a database.
Company interview guides for this role
- Infosys interview questions
- Accenture interview questions
- Capgemini interview questions
- ZS Associates interview questions
- Swiggy interview questions
Related roles and topics
- Java developer interview questions
- Data analyst interview questions
- Data scientist interview questions
- Full stack developer interview questions
- HR interview questions
- Behavioural interview questions
- Coding interview questions
- System design interview questions
- Interview questions for freshers
- Sales interview questions
- All roles →
Practise these questions for your next interview
Add your resume to Cuelyte AI, type a question and get a clear answer in your own words - in English, Hindi or Hinglish. Free to start.