Contents

Python Interview Questions for Developers (Core, OOP, Coding) | OfferBull

Python Interview Questions for Developers (Core, OOP, Coding)

Someone draws is vs == on the board and waits.

You’ve used both. A lot. Under a clock your answer still starts with “so basically,” then never lands the scored bits: when identity matters, when value equality is enough, and why a mutable default quietly ruins a function two calls later.

That’s what python interview questions feel like on a real loop. Not a quiz app with green checks. Core language, OOP, a short coding round, then whatever the JD hints at (FastAPI, Django, data pipelines). Coding patterns still matter: top coding interview patterns. Backend framing: how to prepare for backend engineering interviews. JVM-heavy shops? Keep Java for experienced and Spring Boot open. Data roles often slide into PySpark.

Samples below are made up. Say them out loud. Reading silently won’t kill the filler words.

Core language they actually poke

Mutability, is, and default arguments

Lists and dicts change in place. Tuples and frozensets don’t. Strings don’t either; a “change” is a new object.

== is value. is is identity (same object). Tiny ints and interned strings can make is look right for values. It isn’t a habit you want. Don’t talk like it is.

Mutable default trap:

def append_item(x, bucket=[]):  # bad
    bucket.append(x)
    return bucket

Call it twice. Second call still sees the first list. Fix: bucket=None, then build [] inside.

Spoken: “I don’t use mutable defaults. Shared across calls. I put None, create inside. Equality with ==. Sentinels? is None.”

GIL, concurrency, and when threads help

In CPython, the GIL means one thread runs Python bytecode at a time. Pure CPU work in threads rarely scales. Waiting on network or disk can still help, because a lot of blocking calls drop the lock.

CPU path: multiprocessing, or a library that releases the GIL (NumPy, some C extensions). Many sockets: asyncio or a thread pool, depending on what the team already runs.

Nobody needs a GIL thesis. They need to hear when more threads won’t help, and what you’d try next.

Q: API handler does heavy JSON transforms. Threads didn’t help. Why?

A: “Sounds GIL-bound. Profile first. Then a process pool, or move the hot part into something that already releases the lock. I wouldn’t pile on threads for pure Python math and call that a fix.”

Generators and iterators

Iterators expose __next__. Generators are yield functions that pause. Stream a big file or a cursor and memory stays flat.

yield from hands off to another generator. Generator expressions look like list comps with parentheses: lazy. Not a full list sitting in RAM.

Spoken: “List when I need random access twice. Generator when I’m piping once over a huge input. I once loaded a whole CSV into a list for a one-pass aggregate. Burned RAM for nothing. Not again unless I have a reason.”

Decorators without the mystique

Decorator: takes a callable, returns a callable. @wraps from functools keeps __name__ and the docstring. Class decorators exist; most rooms stick to functions.

They’ll ask for a timing or retry wrapper, or the difference between @property, @classmethod, and @staticmethod.

Q: Why @wraps?

A: “Skip it and the wrapper steals the name and docs. Stack traces look wrong. @wraps(fn) copies the metadata back.”

OOP and typing

Classes, MRO, and dunders they expect

__init__ vs __new__ (rare unless they build immutables). __repr__ for debugging. __eq__ / __hash__ if the object goes in a set. Context managers: __enter__ / __exit__ or @contextmanager.

Multiple inheritance: C3 linearization. You don’t recite the algorithm. You say: ClassName.__mro__, diamond problem exists, prefer composition when the hierarchy gets cute.

Spoken: “I reach for composition before a deep mixin tree. If we already have mixins, I check __mro__ before guessing which save() runs.”

Dataclasses, protocols, and typing that shows up on the job

@dataclass cuts boilerplate. frozen=True when you want hashable records. field(default_factory=list) avoids the mutable default bug again.

Typing: Optional, Union / |, TypedDict, Protocol for duck typing without inheritance. mypy or pyright in CI beats “we type sometimes.”

They rarely want you to invent a full generic library. They want: you annotate public APIs, you know Any is an escape hatch, and you can explain why a Protocol fits a plugin boundary.

/images/posts/python-interview-questions/oop-mutability-walkthrough.jpg OOP / mutability walkthrough on paper. Interviewer hands only.

Coding-round idioms

Python loops get asked with the same shapes as any language: two pointers, sliding window, hash maps, BFS/DFS. The Python flavor is idioms.

Stuff that scores well when it’s natural:

  • Dict / set for O(1) membership
  • collections.Counter, defaultdict, deque
  • Comprehensions that stay readable (one idea, not nested soup)
  • enumerate, zip, unpacking
  • EAFP with a narrow except (not bare except:)
  • Pathlib over raw string paths when file IO shows up

Sample prompt (illustrative): group anagrams.

Spoken approach: “Normalize each word: sort characters, use that as the dict key, append originals to a list. Return the values. Time dominated by sorting each string. Space for the map.”

Then write it. Then test empty input and single-letter words out loud.

Another favorite: merge intervals, top-k with heapq, LRU sketch with OrderedDict or a quick doubly-linked talk-through.

If they say “don’t use the stdlib cheat,” say so and fall back to a plain dict + list. Arguing about whether Counter is allowed wastes the clock.

Backend and data variants

Match the JD. Don’t dump Django middleware into a pure algorithms screen.

Web / API: FastAPI or Django/Flask. Request lifecycle, dependency injection (FastAPI), ORM N+1, migrations, auth (sessions vs JWT), background tasks. Connection pools and timeouts show seniority more than framework trivia.

Data / scripts: pandas gotchas (chained assignment, copies), chunked reads, idempotent jobs, schema drift. If Spark is on the JD, move to PySpark interview questions instead of pretending a notebook answer covers cluster shuffle.

Q: Endpoint slow only under load. Where do you look first?

A: “Metrics: latency percentile, DB time, pool wait. Then query plans and N+1. Then lock contention. I don’t start by rewriting the serializer for fun.”

/images/posts/python-interview-questions/coding-practice-desk.jpg Voice practice with Python notes nearby. Prep tool on the desk, not in a live interview.

/images/posts/python-interview-questions/mutability-model.svg Mental model: mutable list vs immutable tuple, and why defaults bite.

Night-before drill

I’d run these out loud, timer on:

  • is vs ==, plus the mutable default story
  • GIL in two sentences, with one CPU fix and one I/O fix
  • Generator vs list for a 10GB log
  • Decorator with @wraps
  • One anagram or interval problem with tests spoken
  • One production story: N+1, pool exhaustion, or a bad deploy

Behavioral still shows up. Keep STAR ready for a failed migration or a paging incident.

Practicing with OfferBull

Flashcards don’t train the pause before you say “GIL.”

OfferBull is an AI mock interview app for iOS and Android. Voice interviewer. You speak. Paste a Python JD or upload a resume. Follow-ups based on what you said. Suggestions and STAR while you practice. English and Chinese.

Before the interview. Not during.

Start an AI mock interview

FAQ

Do I need CPython internals? Usually no. GIL, reference counting at a high level, and when to use multiprocessing is enough unless the role is interpreter / performance engineering.

asyncio in every interview? Only if the JD or stack uses it. Don’t force coroutines into a sync Django chat.

Typing required? More teams want annotations on public code. Be ready to read and write basic types even if the legacy codebase is loose.

Should I memorize every collections type? Know Counter, defaultdict, deque, namedtuple/dataclass. The rest you can look up on the job; in interview, say what you’d reach for and why.

LeetCode language: Python OK? Usually yes. Confirm. Write clear code, not golf.


Practice This Out Loud

Tonight: mutable defaults in 45 seconds, GIL in 60, one generator use case, one small coding prompt with spoken tests. Record it. Then a voice mock with follow-ups. → Practice Now