Python Tutorial 0/52 lessons ~6 min read Lesson 52
Python Interview Prep
Senior Python interviews mix language depth (GIL, mutability, decorators), data structures, and system design.
Course progress0%
Focus
8 guided sections
Practice signal
Examples included
Career prep
Interview Q&A included
Introduction
Senior Python interviews mix language depth (GIL, mutability, decorators), data structures, and system design. Have crisp 60-second answers ready.
Understanding the topic
Core concepts to understand:
- Mutable vs immutable types — and why it matters.
- List vs tuple vs set vs dict — when which?
- GIL implications.
- Decorators end-to-end.
- Generators / iterators.
- async vs threads vs processes.
Syntax reference
Visual flow / code:
python
# Be ready to write live:# 1. LRU cache from scratchfrom collections import OrderedDictclass LRU:def __init__(self, cap): self.cap, self.d = cap, OrderedDict()def get(self, k):if k not in self.d: return -1self.d.move_to_end(k); return self.d[k]def put(self, k, v):if k in self.d: self.d.move_to_end(k)self.d[k] = vif len(self.d) > self.cap: self.d.popitem(last=False)# 2. Timing decorator (see Decorators lesson)# 3. async fetch many URLs (see async lesson)
Execution workflow
1Python Interview Prep Workflow
1 / 4Mutable vs immutable types
and why it matters.
Real-world use
FAANG and scale-up interviews routinely ask: 'implement LRU cache', 'rate-limiter', 'producer-consumer with asyncio'. Practice these patterns until muscle memory.
Best practices
- Memorize 3 canonical patterns: LRU cache, decorator, async gather.
- Be ready to explain GIL + when to use processes/async/threads.
- Bring a real war story: a bug you debugged or a perf win.
Advanced interview questions
Interview Prep
Practice concise answers, then expand each card for the explanation.
1IntermediateQuestionWhy is Python slow? How would you speed it up?+
Answer
Python is not slow in every case, but CPython is slower for tight CPU loops because it interprets bytecode, uses dynamic typing, and boxes every value as an object; the GIL also limits thread parallelism. First profile, then improve algorithms and data structures, use built-ins and vectorized NumPy, cache results, use multiprocessing for CPU work or asyncio for I/O, and move hot loops to Cython, Numba, or Rust.
Follow-up
Which of those would you try first, and why?
2IntermediateQuestionExplain the GIL.+
Answer
The GIL is a lock in the default CPython build that allows only one thread to run Python bytecode at a time, which keeps reference counting and interpreter internals safe. Threads can still overlap during blocking I/O and in C extensions that release the lock, but CPU-bound Python code does not get parallel speedup from threads. Use processes for that. Python 3.13 added an experimental free-threaded build without the GIL.
Follow-up
Does the GIL remove the need for locks in threaded code?
3BeginnerQuestionHow do decorators work?+
Answer
A decorator is a callable that takes a function and returns a new callable, and
@deco on a function is syntactic sugar for f = deco(f) at definition time. Typically the returned wrapper calls the original with *args, **kwargs and adds behavior around it. Use functools.wraps to preserve metadata, and add an extra outer function when the decorator takes arguments.Follow-up
How would you write a decorator that times a function?
4BeginnerQuestionList vs generator — when?+
Answer
Use a list when you need random access, a known length, multiple passes, or to keep all items. Use a generator when items can be processed one at a time, especially for large or unbounded streams, because it computes values lazily and holds only one in memory. A generator is single-use, has no
len() or indexing, and may be slower overall if you end up materializing it anyway.Follow-up
How does a generator expression differ from a list comprehension?
5AdvancedQuestionHow do you design a rate limiter in Python?+
Answer
Pick an algorithm, usually token bucket for allowing bursts, or a sliding window for stricter limits. In a single process, track per-key state in memory under a lock or in one event loop. Across instances, keep the counters in Redis with atomic operations or a Lua script, and set key expiry. Return HTTP 429 with a
Retry-After header, and decide whether to fail open or closed if the store is down.Follow-up
How would you rate limit per user and per IP at once?
Summary
In summary: Practice LRU, decorators, async live-coding. Know GIL trade-offs cold. Bring a real story.
Ready to mark this lesson complete?Track your journey across the entire course.