Guide Python Intermediate

11.15 Interview Questions

Frequently asked and scenario-based Python tuple interview questions covering tuple vs list, why (1) isn't a tuple, hashability, and classic coding problems like the temp-variable-free swap and multi-value returns.

2 min read

Conceptual Questions

  • What’s the difference between a tuple and a list?
  • Why does (1) not create a tuple, but (1,) does?
  • Why are tuples hashable but lists are not?
  • Can a tuple contain mutable objects? What are the implications?
  • Why is tuple creation generally faster than list creation?

Scenario-Based Questions

  • A fixed set of valid AWS regions should never be modified at runtime — would you use a tuple or a list, and why?
  • A tuple contains a list as one of its elements — is the tuple hashable? Why or why not?
  • Three values need to be returned from a function — what’s the idiomatic way to do this in Python, and how would the caller consume it?

Coding Questions

  • Write a function that swaps two variables’ values using tuple packing/unpacking, without a temporary variable.
  • Given a tuple of mixed types, write code that safely determines whether it’s hashable.
  • Write a function returning both the min and max of a tuple in a single call, using multiple return values.
def minmax(t):
    return min(t), max(t)

>>> minmax((5, 2, 8, 1))
(1, 8)

Quick Interview Answer

“Tuple questions cluster around three things: immutability and its consequences (hashability, safety from accidental change, why (1) isn’t a tuple but (1,) is), the tuple-vs-list decision (fixed record vs. growable collection, dict-key eligibility), and the packing/unpacking idioms that show up constantly in real code — the temp-variable-free swap, and returning multiple values from a function as an implicit tuple. The hashability scenario question is a good one to prepare precisely: a tuple is hashable only if every element inside it is also hashable, so a tuple containing a list is not.”

Common Mistakes

  • Answering “tuples and lists are basically interchangeable, just pick either” without mentioning mutability, hashability, or when each is structurally the correct choice.
  • Solving the swap question by declaring a temporary variable — missing the entire point that a, b = b, a packs the right side into a tuple before any assignment happens.
  • Forgetting hashability is contents-dependent, not automatic for every tuple — answering “yes, all tuples are hashable” without the caveat about nested mutable elements.

Add More Questions to This Guide

Know a question that should be here? Share it and help the community!

Open Google Form