Python Developer Interview Questions and Answers

Python interviews start with the language itself: data types, mutability, comprehensions, decorators and generators. Backend roles then move to Django or Flask, REST APIs and databases; most also include a coding round.

Interviewers like candidates who write idiomatic Python, so practise solving problems with the standard library instead of re-inventing it.

Python Developer interview rounds

  1. Coding screen. 1–2 problems on strings, lists and dictionaries, sometimes on HackerRank or a shared editor.
  2. Python round. Language internals: mutability, scope, decorators, generators, GIL, OOP.
  3. Framework / backend round. Django or Flask, REST APIs, ORM queries, authentication and your project.
  4. HR / managerial. Experience, expectations and team fit.

Core Python interview questions

List vs tuple?

Lists are mutable and tuples aren't. Tuples are hashable when their items are, so they can be dictionary keys, and they're slightly faster and lighter. Use tuples for fixed records, lists for collections that change.

What are mutable default arguments, and why are they a problem?

Default values are created once when the function is defined. A default like items=[] is shared between calls, so appends pile up. Use items=None and create the list inside the function.

Shallow vs deep copy?

A shallow copy (copy.copy, list slicing) copies the outer object but shares the inner ones. A deep copy (copy.deepcopy) copies everything recursively, so changes to nested objects don't leak.

What is the GIL?

The global interpreter lock lets only one thread run Python bytecode at a time in CPython. Threads still help with I/O-bound work; for CPU-bound work use multiprocessing or native extensions.

*args and **kwargs?

*args collects extra positional arguments into a tuple; **kwargs collects extra keyword arguments into a dict. They let a function accept a flexible signature, and pass arguments through to another function.

Functions, OOP and iterators interview questions

What is a decorator?

A function that takes a function and returns a new one that wraps it, used for logging, caching, authentication or timing. Use functools.wraps so the wrapped function keeps its name and docstring.

Generator vs list?

A generator yields items one at a time and keeps only its current state, so it uses almost no memory for large or infinite sequences. A list holds every item at once.

What are @staticmethod and @classmethod?

A staticmethod gets no automatic first argument; it's a plain function inside the class. A classmethod gets the class (cls), so it's used for alternative constructors like from_json.

How does Python resolve methods with multiple inheritance?

By the method resolution order (MRO), computed with C3 linearisation: the class itself, then parents left to right, without visiting a base before its subclasses. Check it with ClassName.__mro__.

What is a context manager?

An object with __enter__ and __exit__, used with 'with' to set up and always clean up a resource, like closing a file or releasing a lock even if an exception is raised.

Django, Flask and APIs interview questions

Django vs Flask?

Django is batteries-included: ORM, admin, auth and migrations out of the box, good for full applications. Flask is minimal and you choose the pieces, good for small services and APIs.

select_related vs prefetch_related in Django?

select_related follows foreign keys with a SQL JOIN in one query. prefetch_related runs a separate query for many-to-many or reverse relations and joins in Python. Both fix N+1 queries.

How does Django middleware work?

Middleware classes wrap every request and response in order: each can act before the view runs and after it returns, for things like sessions, authentication, CSRF checks or logging.

How do you secure a REST API?

Authentication with tokens or JWTs, permission checks on every endpoint, input validation, HTTPS, rate limiting, and never trusting IDs from the client without checking ownership.

Coding interview questions

Find the first non-repeating character in a string.

Count characters with collections.Counter, then loop through the string and return the first with count 1. O(n) time.

Merge two sorted lists.

Walk both with two pointers, appending the smaller item each time, then append what's left; or use heapq.merge for an iterator. O(n + m).

How Aptivo answers a Python Developer question live

During a real interview, Aptivo hears the question and shows an answer built from your resume and the job, a few seconds after the interviewer finishes. Something like this:

InterviewerCan you explain what a decorator is and give an example?

AptivoA decorator wraps a function to add behaviour without changing its code. For example, a timing decorator: def timed(fn): @wraps(fn) def inner(*args, **kwargs): start = time.perf_counter(); result = fn(*args, **kwargs); print(fn.__name__, time.perf_counter() - start); return result; return inner. Then @timed above any function logs how long it takes. In my project I used the same pattern to check API keys on Flask routes.

Read it, then say it in your own words. Answers mention your own projects when your resume has them.

Tips for your Python Developer interview

  • Solve practice problems in idiomatic Python: Counter, defaultdict, sorted with key, comprehensions.
  • Be ready to explain one framework in depth, including how a request flows through it.
  • Know your ORM: how to avoid N+1 queries and when to drop to raw SQL.
  • Mention tests: pytest, fixtures and what you mocked in your project.

Frequently asked questions

What Python topics are asked for freshers?

Data types and mutability, lists vs tuples, dictionaries, comprehensions, functions and *args/**kwargs, basic OOP and exception handling, plus simple coding problems.

Do I need Django for a Python developer job?

For backend roles, usually Django, Flask or FastAPI. Learn the one the job post names, and be able to build and explain a small REST API with it.

How hard is the coding round?

For most service companies it's easy to medium: strings, arrays, hash maps. Product companies go further into trees, graphs and dynamic programming.

Interview questions for other roles