Interview questions

Python Cheat Sheet Interview: Containers, Equality, and Common Traps

July 31, 2025Updated May 15, 202619 min read
Is A Python Cheat Sheet Pdf The Missing Link In Your Coding Interview Strategy

Use this Python cheat sheet interview guide to cover containers, equality, and common traps in the order interviewers probe them first.

Most people preparing for a Python technical interview don't have a learning problem. They have a prioritization problem. A good python cheat sheet interview guide doesn't need to cover every corner of the language — it needs to tell you which corners interviewers actually walk into first, and in what order. That's what this is.

The reality is that interviewers probe Python in a predictable sequence. They start with containers and mutability because that's where shallow understanding shows up fastest. They follow with equality and identity because that's where confident-sounding candidates get quietly tripped up. They finish with iteration, copy behavior, and performance tradeoffs because those separate people who've used Python from people who've only read about it. If you can talk fluently through that sequence, you'll cover the overwhelming majority of what a screening round actually tests.

Study Python in the order interviewers actually probe it

Start with containers before you touch clever syntax

Interviewers start with containers — lists, tuples, sets, and dictionaries — because they're the fastest diagnostic available. A candidate who can explain why they'd reach for a set instead of a list, or why a tuple signals immutability by design, is already demonstrating something more valuable than syntax recall: they're showing they understand how Python stores and changes data. That's the foundation everything else sits on.

The priority order for Python interview prep is not alphabetical and it's not comprehensive. It's frequency-weighted. Containers come first. Mutability and argument behavior come second. Equality and identity come third. Copy semantics and iteration come fourth. Big-O tradeoffs on built-ins come last, and only because they occasionally close out a round.

Why mutability keeps coming back in different disguises

Mutability isn't one question — it's a thread that runs through at least five different questions interviewers ask. It shows up when they ask how Python passes arguments. It shows up when they ask about mutable default arguments. It shows up when they ask about aliasing. It shows up when they ask about shallow versus deep copy. It shows up when they ask why two variables that look equal don't behave identically.

Once you understand that lists are mutable and tuples are not, and that Python passes object references rather than copies, most of those questions collapse into the same underlying answer. That's the leverage point. Treat mutability as a theme, not a topic.

What this looks like in practice

If you have one evening left, this is the order: containers and their tradeoffs, then mutable versus immutable types, then how Python passes arguments, then `==` versus `is`, then mutable defaults, then copy behavior, then generators and iteration, then Big-O for built-ins. That's it. A senior engineer who screens Python candidates regularly will tell you the first four topics cover roughly 70% of what actually gets asked in a 45-minute screening round. The rest is context-dependent.

The 80/20 Python fundamentals interviewers keep returning to

The small set of concepts that carries most interviews

Python fundamentals interview questions tend to cluster around five areas: data types and containers, control flow, functions and argument behavior, exception handling, and iteration. Depth matters more than breadth here. An interviewer who asks about list comprehensions isn't looking for a definition — they're listening for whether you can explain the tradeoff between readability and memory, or when a generator expression would be the better choice.

According to Python's official documentation, the language is designed around a small set of core abstractions that compose cleanly — and that's exactly the model interviewers are testing for. Can you explain how those abstractions interact, not just what they're called?

The polite version of "I know Python" that actually holds up

The answers that hold up under follow-up questions are the ones that demonstrate reasoning, not recall. Take a simple task: filtering values from a list and handling a missing key in a dictionary. A weak answer names the syntax. A strong answer explains why `dict.get(key, default)` is safer than direct key access, and why a list comprehension is more Pythonic than a for-loop with an append — and also when it isn't, like when the list is very large and you only need to iterate once.

That's the difference between sounding memorized and sounding like someone who has actually written Python under production constraints.

What this looks like in practice

In a typical screening round, a candidate might be asked to write a loop that processes a list of user inputs, skips invalid entries, and handles a `KeyError` gracefully. The interviewer isn't watching for perfect syntax — they're watching for whether the candidate uses a `try/except` block intentionally, whether they know what exceptions to catch narrowly rather than broadly, and whether they can explain their choices without being prompted. That's non-negotiable for junior and mid-level candidates: you need to be able to explain a loop, a conditional, and an exception handler without turning it into a tutorial.

Make lists, tuples, sets, and dictionaries sound like interview answers, not flashcards

The tradeoff interviewers actually want you to name

The question behind every container question is: do you understand the tradeoff this structure makes? Lists give you ordered, mutable sequences — good for indexed access and appending, slower for membership testing. Tuples give you ordered, immutable sequences — useful when you want to signal that data shouldn't change, and slightly more memory-efficient. Sets give you unordered collections of unique elements — O(1) membership testing, no duplicates, no guaranteed order. Dictionaries give you key-based lookup — O(1) average-case access, ordered by insertion since Python 3.7.

When you can name those tradeoffs in a sentence each, the interviewer stops testing containers and moves on. When you can't, they keep probing.

Where candidates get too shallow with container questions

The common failure mode is reciting definitions. "A list is mutable and ordered. A tuple is immutable and ordered. A set is unordered and unique." That's a flashcard, not an interview answer. What's missing is the why. Why would you use a set for deduplication? Because membership testing is O(1) and the deduplication is automatic — you don't need to write a loop. Why would you use a tuple instead of a list for a function return value? Because it signals to the caller that the data is fixed, and it's hashable, which matters if you need to use it as a dictionary key.

The Python documentation on built-in types is precise about these behaviors — and precision is exactly what interviewers are listening for.

What this looks like in practice

Here's a scenario that comes up: you have a list of names with duplicates, and you need to deduplicate them while preserving the original insertion order. A candidate who reaches immediately for `set(names)` gets the deduplication right but loses the order. A stronger answer is `list(dict.fromkeys(names))` — which preserves insertion order using the dictionary's key behavior. That's the kind of answer that shows you understand how the containers actually work, not just what they're called.

Stop mixing up == and is

Why this question is never really about syntax

When an interviewer asks about `==` versus `is`, they're not testing whether you know the operators exist. They're testing whether you understand the difference between value equality and object identity — and whether you know when Python's interning behavior can make `is` return `True` in ways that look correct but aren't reliable. The real diagnostic is: does this candidate understand that two objects can be equal in value while being distinct in memory?

The aliasing mistake that makes weak answers obvious

Aliasing is where this gets concrete. When you write `b = a` for a mutable object like a list, `b` and `a` point to the same object in memory. So `b is a` returns `True`, and mutating `b` also mutates `a`. That's not a coincidence — it's the expected behavior. But candidates who haven't thought through identity versus equality will explain this as a quirk rather than as a consequence of how Python manages references. The aliasing behavior is the same mechanism that makes mutable default arguments dangerous, which is why interviewers often ask about both in the same round.

What this looks like in practice

Small integers and interned strings complicate this further. `x = 256; y = 256; x is y` returns `True` because CPython caches small integers. `x = 257; y = 257; x is y` may return `False` in some environments. That's why `is` should only be used to compare against singletons like `None`, `True`, and `False` — never for general equality checks. That's the answer interviewers are hoping to hear.

Explain mutable default arguments without sounding memorized

Why this bug still catches people who know the rule

The mutable default argument problem trips up people who know the rule because they've memorized the fix without understanding the mechanism. The real explanation is this: Python evaluates default argument values once, at function definition time, not at call time. So if the default is a mutable object like a list, that same list object is reused across every call that doesn't pass an explicit argument. The bug isn't the syntax — it's the lifecycle of the default object.

The safer answer interviewers hope you give

The standard fix is to use `None` as the default and create the mutable object inside the function body:

But the answer interviewers actually want to hear is the explanation of why this works: because `None` is immutable and the list is created fresh on each call, rather than persisting across calls. The fix is the easy part. Understanding the lifecycle is the point.

What this looks like in practice

The second call returns `['a', 'b']` because the default list persisted from the first call. That's the gotcha. Once you've seen it behave this way in a live shell, you stop treating it as an abstract rule. Python's FAQ on mutable default arguments covers the exact evaluation timing that causes this.

Shallow copy, deep copy, and the part people skip

The structural difference that matters in interviews

Shallow copy duplicates the outer container but leaves the inner objects as references to the originals. Deep copy duplicates everything, recursively. That distinction doesn't matter for flat structures — a shallow copy of a list of integers behaves like a full copy. It matters the moment you have nested structures: a list of lists, a dictionary of lists, any object that contains other mutable objects.

Why this question shows up with nested lists and dicts

Interviewers reach for nested structures specifically because that's where shallow copy behavior produces surprising results. If you shallow-copy a list that contains another list, mutating the inner list in the copy also mutates the original. That's not a bug in Python — it's the documented behavior of `list.copy()`, the slice `[:]`, and `copy.copy()`. The only way to get a fully independent copy is `copy.deepcopy()`.

What this looks like in practice

The Python copy module documentation is explicit about this behavior. When you can walk through that example without hesitation, you've answered the question at the level interviewers are actually testing.

Talk about iteration and generators like someone who has used them

Why interviewers care about iterators before they care about syntax

The real diagnostic with iteration questions is whether the candidate understands the protocol: an iterable is anything that can return an iterator; an iterator is an object with a `__next__` method that returns values one at a time until `StopIteration`. A for-loop is just syntactic sugar over that protocol. Understanding this means you can explain why a generator is useful — it's not magic, it's a lazy iterator that produces values on demand instead of building the whole sequence in memory first.

How to explain generators without making them sound magical

A generator is a function that uses `yield` instead of `return`. Each call to `next()` on the generator runs the function until the next `yield`, pauses there, and returns the value. The state of the function — local variables, execution position — is preserved between calls. That's it. The practical payoff is memory efficiency: if you're reading a large file line by line, a generator produces one line at a time rather than loading the entire file into a list.

What this looks like in practice

The generator expression uses parentheses instead of brackets. The syntax is nearly identical, but the memory profile is completely different. The Python documentation on generators covers this precisely. In an interview, the right answer to "when would you use a generator?" is: when you need to iterate over a large or potentially infinite sequence and you don't need random access or multiple passes.

Give a straight answer on performance without turning it into Big-O theater

The only performance tradeoffs that really matter here

For Python built-ins, the Big-O tradeoffs for Python built-ins that come up most often are: list append is O(1) amortized, list search is O(n), dict and set lookup are O(1) average case, and tuple access is O(1). Those four facts cover the vast majority of performance questions in a screening round. The interviewer isn't expecting a recitation of the full time complexity table — they're checking whether you know why a set is faster than a list for membership testing, and whether you'd reach for the right tool without being prompted.

When a simple answer is better than a clever one

If the question is "how would you check whether an email address already exists in a collection of a million addresses," the right answer is a set, not a list. The explanation is one sentence: set membership is O(1) because it's backed by a hash table, while list membership requires scanning every element. That's the reasoning the interviewer wants. Launching into a discussion of hash collision resolution or amortized analysis is usually not what's being asked for, and it can read as deflection from a simpler answer.

What this looks like in practice

A candidate asked to deduplicate a list of emails and check membership efficiently should land on a set or a dictionary keyed by email address. The set is cleaner if you only need membership. The dictionary is better if you need to store metadata per email. Choosing between them and explaining the reasoning out loud — "I'd use a set here because I only need to check existence and I want O(1) lookup" — is the complete answer.

End with a cram order that feels calm, not frantic

The one-page order to review before the interview

This is the Python revision sheet compressed to its essentials. Start with containers: list, tuple, set, dict — know the tradeoffs cold. Move to mutability: which types are mutable, what that means for function arguments, what happens when two variables reference the same object. Then equality and identity: `==` versus `is`, when each is appropriate, and why `is` only belongs with singletons. Then mutable defaults: the lifecycle explanation, the `None` sentinel pattern. Then copy behavior: shallow copies the outer container, deep copies everything. Then iteration: the iterator protocol, when generators save memory. Then Big-O for the four built-ins that matter. That's the full circuit.

What to do when you have only 20 minutes left

Skip everything except the traps. Read through the mutable default argument example. Read through the `==` versus `is` REPL example. Read through the shallow copy example with the nested list. Those three are the most common places where candidates who know Python still give weak answers, because they've learned the rule without internalizing the mechanism. If you can explain each one out loud in plain English — not recite the rule, but explain what's actually happening — you're in good shape.

What this looks like in practice

Run through this checklist aloud before the interview:

  • Containers: list is ordered and mutable, tuple is ordered and immutable, set is unordered and unique with O(1) lookup, dict is key-value with O(1) average lookup and insertion order preserved.
  • Mutability: Python passes object references. Mutating a mutable argument inside a function mutates the original.
  • Equality vs identity: `==` compares values, `is` compares object identity. Only use `is` for `None`, `True`, `False`.
  • Mutable defaults: default objects are created once at definition time. Use `None` as sentinel and create the mutable object inside the function.
  • Copy behavior: `copy.copy()` is shallow — nested objects are still shared. `copy.deepcopy()` is fully independent.
  • Generators: produce values lazily, one at a time. Use when memory matters or when iterating over a large sequence.
  • Performance: list search is O(n), set and dict lookup are O(1). Pick the right container before optimizing anything else.

A senior engineer screening Python candidates would expect every junior and mid-level candidate to have those seven points cold. Not as a recitation — as a working model they can apply to a problem they've never seen before.

FAQ

Q: What Python fundamentals are most likely to come up in an interview, and in what order should I study them?

Start with containers (list, tuple, set, dict) and their tradeoffs, then move to mutability and argument passing, then equality versus identity, then mutable default arguments, then copy behavior, then iteration and generators, then Big-O for built-ins. That sequence mirrors the order interviewers actually probe, with containers and mutability covering the majority of screening-round questions.

Q: What are the most common Python mistakes candidates make when answering basic interview questions?

Three mistakes dominate: confusing `==` with `is` without understanding the identity versus value distinction, using a mutable default argument without being able to explain why it persists across calls, and giving a shallow copy answer that skips the behavior with nested objects. All three are simple in principle and easy to get wrong under pressure because people memorize the fix without internalizing the mechanism.

Q: How do list, tuple, set, and dictionary differ in a way that matters in interviews?

Lists are ordered and mutable — good for indexed access and appending, O(n) for membership. Tuples are ordered and immutable — signals fixed data, hashable, slightly more memory-efficient. Sets are unordered, unique, and O(1) for membership — best for deduplication and fast existence checks. Dicts are key-value with O(1) average lookup and insertion-ordered since Python 3.7. The interviewer wants to hear which tradeoff you're optimizing for, not just the definition.

Q: When should I use == versus is, and why do interviewers ask this?

Use `==` to compare values. Use `is` only to compare against singletons: `None`, `True`, `False`. Interviewers ask because it surfaces whether you understand object identity versus value equality — and because CPython's interning of small integers and strings can make `is` appear to work correctly in cases where it isn't reliable, which is exactly the kind of subtle behavior that separates candidates who've thought about the language from those who've only used it.

Q: What should I say if asked about mutable default arguments or shallow versus deep copy?

For mutable defaults: explain that the default object is created once at function definition time and reused across calls, then show the `None` sentinel pattern and explain why it works — the list is created fresh each call. For copy behavior: explain that shallow copy duplicates the outer container but keeps inner objects as shared references, while deep copy duplicates the full structure recursively. In both cases, the mechanism matters more than the fix.

Q: Which Python topics matter most for junior engineers versus interviewer prepper roles?

Junior and mid-level candidates should be able to explain containers, mutability, argument passing, `==` versus `is`, and basic exception handling without prompting — those are considered non-negotiable in most screening rounds. Interviewer preppers need the same map, plus a sense of which topics reliably separate strong candidates from weak ones: mutable defaults, copy behavior, and generator usage are the most diagnostic because they require understanding, not just recall.

Q: How can I quickly refresh Python syntax and core concepts right before an interview?

Use the seven-point checklist in the final section of this article and run through it out loud. Don't read — explain each point to yourself as if someone asked you the question. If you stumble on the explanation, that's the gap to close. Twenty minutes of that is more useful than an hour of passive reading.

How Verve AI Can Help You Ace Your Coding Interview With Python

The hardest part of Python interview prep isn't knowing the concepts — it's being able to explain them clearly under live pressure, when a follow-up question comes from a direction you didn't anticipate. That's a performance skill, and it only develops through practice that responds to what you actually say, not a script you prepared for.

Verve AI Coding Copilot is built for exactly that gap. It reads your screen during live technical rounds and mock sessions — whether you're working through a problem on LeetCode, HackerRank, or CodeSignal, or in a live interview — and responds to what's actually happening in the session. If you're halfway through explaining a shallow copy and you've left out the nested object behavior, Verve AI Coding Copilot can surface the gap in real time. If you've chosen a list where a set would be faster, it can prompt the reasoning before the interviewer does.

The Secondary Copilot feature is particularly useful for Python fundamentals work: it lets you stay focused on a single problem — say, explaining the mutable default argument lifecycle — and drill the explanation until it sounds natural rather than rehearsed. Verve AI Coding Copilot suggests answers live without being visible to the interviewer, so you can use it in practice rounds that mirror the real pressure of a screening call. The goal isn't to have the tool answer for you — it's to use it to identify exactly where your explanation breaks down before the interview does.

---

The goal of this guide was never to teach you all of Python. It was to show you the small set of concepts that keeps coming up, in the order they actually come up, so you can walk into a screening round without getting derailed by questions you know the answer to but haven't thought through clearly. Skim the one-page cram order once. Then close the browser and explain each point out loud. That's the prep that actually holds up when the follow-up question arrives.

QO

Quinn Okafor

Interview Guidance

Ace your live interviews with AI support!

Get Started For Free

Available on Mac, Windows and iPhone