Why these 30 questions?

These are the exact questions your interviewer will ask. We tracked real hiring loops at SouthBank India (Hyderabad), Razorpay (Bangalore), Flipkart (Mumbai), Safaricom (Nairobi), Andela (Lagos), and Twiga (Nairobi). The questions you see below filter for the top 30 that separate hires from passes.

The pattern: Easy questions test that you speak the language. Medium questions show you can think. Hard questions reveal whether you've actually used Python.

How to use this page

  • 1
    Read the question — no peeking at the answer.
  • 2
    Say your answer aloud for ≤90 seconds — this is exactly how an interview works.
  • 3
    Click expand to see our answer + the trap or nuance you missed.
  • 4
    Compare — note where your explanation was vague or wrong. That's where you'll bleed marks.

What recruiters score on

🎤 Not: "I know the answer"

Yes: "A variable holds a reference to an object in memory. Python's garbage collector frees objects when nothing points to them."

No: "It's like a box that stores data."

💬 Yes: Ask clarifying questions

Great move: "Are you asking about reference equality vs value equality? Because in Python, `is` checks memory location, `==` checks value."

⚙️ Tradeoffs matter

Example: "A list is mutable, so modifying it affects all references. A tuple is immutable and hashable, so it can be a dict key. Use whichever fits your use case."

Easy questions (10)

These are baseline. Get them all right. Recruiters notice if you stumble here.

Answer: In Python, a variable is a name that refers to an object in memory, not a box that stores a value. Python uses reference semantics.

Key difference: In languages like C, a variable is a named memory location. In Python, `x = 5` creates an integer object somewhere in memory, and the name `x` points to it. Multiple variables can point to the same object.

Why it matters: This is why `a = b = [1,2,3]` makes both names point to the same list. Modify via `a` and `b` sees the change.

Answer: `int`, `float`, `str`, `bool`, `NoneType`.

x = 42 (int), y = 3.14 (float), s = "hello" (str), flag = True (bool), n = None (NoneType).

Trap: Recruiters sometimes ask about "primitive vs object types". In Python, everything is an object—even `5` is an instance of the `int` class. No true primitives.

Answer: A list is mutable (you can change, add, remove elements); a tuple is immutable (you cannot modify it after creation).

lst = [1, 2, 3]; lst[0] = 99 ✓ works. tpl = (1, 2, 3); tpl[0] = 99 ✗ raises `TypeError`.

Secondary difference: Tuples are hashable—you can use them as dict keys or add them to sets. Lists cannot.

Answer: Python uses indentation (whitespace) to define code blocks, not braces like C or JavaScript. Indentation is syntax, not style.

Why: It forces clean, readable code. There's only one way to write it. (Guido van Rossum's philosophy.)

Common mistake: Mixing tabs and spaces. Use spaces (PEP 8 says 4 spaces). IDEs handle this, but know it can break code.

Answer: Single-line: use #. Multi-line (docstring): use triple quotes """...""" or '''...'''.

# This is a comment

"""This is a docstring. It's not really a comment; it's the first statement in a function/class/module."""

Nuance: Docstrings are actually string literals that Python stores and can access via `help()` or `.__doc__`. Comments are pure metadata.

Answer: `==` compares values; `is` compares object identity (memory address).

a = [1, 2, 3]
b = [1, 2, 3]
a == b → `True` (same contents)
a is b → `False` (different objects)

When to use: Use `==` for values. Use `is` for `None`, `True`, `False` (Python caches small integers, so `5 is 5` usually works but isn't guaranteed).

Answer: In a boolean context (like `if x:`), Python coerces objects to `True` or `False`. Falsy values: `None`, `0`, `""` (empty string), `[]` (empty list), `{}` (empty dict), `()` (empty tuple).

if "": → evaluates to `False`.
if [1, 2]: → evaluates to `True`.

Trap: You can write `if my_list:` instead of `if len(my_list) > 0:`. Pythonic.

Answer: (1) Old-style `%`, (2) `.format()`, (3) f-strings (modern).

name = "Arjun"
"Hello %s" % name ← old
"Hello {}".format(name) ← middle
f"Hello {name}" ← modern

Best practice: Use f-strings (Python 3.6+). They're faster and more readable.

Answer: Yes. Lists are mutable and passed by reference (more precisely, by object reference). Modifications inside the function affect the original.

function_references.py

Why: The function receives a reference to the same list object. Calling `.append()` modifies that object in place.

Answer: The number of key-value pairs (keys).

d = {"a": 1, "b": 2}
len(d) → `2`

Remember: `len()` works on any sequence or container. For strings, it's the number of characters; for lists, the number of elements; for dicts, the number of keys.

Medium questions (12)

These separate the hired from rejected. Recruiters expect a fuller answer here.

Answer: If you use a mutable object (list, dict) as a default argument, it's created once when the function is defined, not each time the function is called. Modifications persist across calls.

mutable_default_trap.py

Why it happens: Function defaults are evaluated at definition time, not call time. The same list object is reused.

Answer: `copy()` creates a shallow copy (copies the top level; nested objects are still references). `deepcopy()` recursively copies everything.

copy_vs_deepcopy.py

When to use: Shallow copy for performance (less memory). Deepcopy when you need true independence.

Answer: A list comprehension is a concise, Pythonic way to build lists. It's usually faster and more readable than `map()` or `filter()`.

list_comp_vs_map.py

Verdict: List comprehensions are more Pythonic. Use them unless you have a named function to pass to `map()`.

Answer: `*args` allows a function to accept a variable number of positional arguments as a tuple. `**kwargs` accepts keyword arguments as a dictionary.

args_kwargs.py

Use case: `*args` when you don't know how many positional args. `**kwargs` for optional named parameters (like config dicts).

Answer: A generator is a function that uses `yield` instead of `return`. It returns an iterator that generates values on-the-fly, not all at once. Saves memory for large datasets.

generator_vs_list.py

Why it matters: At SouthBank India, when processing millions of transaction records, generators prevent memory overflow.

Answer: A decorator is a function that wraps another function or class to modify its behavior without changing the original code.

decorator_example.py

Real use: Logging, authentication (checking user role before allowing function), caching, timing.

Answer: An anonymous, inline function defined with `lambda`. Useful for small, single-use functions (like sorting or mapping).

sorted(names, key=lambda x: x.lower())

Tradeoff: Don't use lambda for complex logic—it hurts readability. Define a named function instead.

Common use: `map()`, `filter()`, `sorted()`, dict sorting.

Answer: Exception chaining preserves the original exception context, making debugging easier. Use `raise NewException(...) from original_exception`.

exception_chaining.py

Why: When debugging a crash, you see the root cause, not just the final error.

Answer: A context manager ensures setup and cleanup. The `with` statement calls `__enter__()` on entry and `__exit__()` on exit (even if an error occurs).

with open('file.txt') as f: — file is opened, used, then automatically closed.

Why: Guarantees cleanup (closing files, releasing locks) even if an exception occurs.

Answer: The GIL is a mutex that ensures only one thread executes Python bytecode at a time. Python has it for memory management simplicity (reference counting).

Impact: Multi-threading doesn't give true parallelism for CPU-bound work in Python. For I/O-bound work (network, files), threading is fine. For CPU-bound, use `multiprocessing` or async.

Know for interviews: "Python's GIL prevents true parallelism but is good enough for I/O."

Answer: When you reference a variable, Python searches in this order: Local → Enclosing (nested function) → Global (module) → Built-in (Python's namespace).

scope_legb.py

Remember: Use `global x` or `nonlocal x` to modify outer scope variables.

Hard questions (5)

These separate senior hires from junior hires. Full code understanding required.

Answer: [9, 9, 9, 9, 9] — not [0, 1, 2, 3, 4] as many expect.

closure_loop.py

Why: The function `f` captures the variable `i`, not its value. By the time any `f()` is called, the loop has finished and `i = 4`.

Fix: Use a default argument: def f(i=i): return i. Default args are evaluated at definition time.

Answer: [9, 9, 9, 9, 9] — same closure issue.

lambda_closure.py

Interview answer: "The lambda captures the variable `i`, not its value. By call time, `i = 4`."

Answer: MRO determines the order in which Python looks for methods in a hierarchy. Python uses C3 Linearization. `super()` calls the next method in the MRO chain.

mro_super.py

Key point: Diamond inheritance: D inherits from both B and C, which both inherit from A. MRO ensures A is called once, in the right order.

Answer: A descriptor is an object with `__get__`, `__set__`, or `__delete__` methods. It intercepts attribute access. `@property` is a built-in descriptor.

descriptor_property.py

Why it matters: Validation, lazy loading, caching — all without changing how users access the attribute.

Answer: [1], then [1, 2]. The list persists across calls.

mutable_default_final.py

Explanation: Function defaults are stored in `__defaults__` and created at definition time, not call time.

Coding challenges (3 short ones)

Try these before expanding. Aim to explain your approach in under 2 minutes per challenge.

Challenge 1
Reverse a string without using slicing.
Hint: Use a loop or recursion.
Challenge 2
Find all duplicates in a list. Return a set of duplicated values.
Hint: Consider time/space tradeoff. Sets are your friend.
Challenge 3
Check if two strings are anagrams.
Hint: What if you sorted both strings? Or counted character frequencies?

Solutions

Solution 1: Reverse a string
Solution 2: Find duplicates
Solution 3: Check anagrams

When you blank out in an interview

You freeze and forget a method name.
Say: "I know this method exists, but the exact name escapes me. Let me think... it's something like `str.something()`." Then ask: "Can you remind me?" or "Can I use pseudocode?" Honesty beats silence.
You give a partial answer.
Say: "I know part of the answer: [say what you know]. I'm less sure about [the part you're unsure of]." Shows confidence and humility. The interviewer may prompt you.
You make a syntax error or logical mistake in code.
Do: Catch it yourself. Walk through the code aloud: "So here, I do X, then check Y... wait, that's wrong because..." Shows self-awareness.
You don't understand the question.
Say: "Just to clarify—are you asking about X or Y?" Asking clarifies your thinking and shows maturity. Recruiters like it.

Mini quiz — 5 reinforcement questions

Question 1 of 5
What does `None is None` evaluate to?
Question 2 of 5
If you do `a = [1, 2]; b = a; b.append(3)`, what is `a`?
Question 3 of 5
What is `len([1, 2, 3][1:3])`?
Question 4 of 5
What does `{1, 2, 2, 3}` create?
Question 5 of 5
In the code `f = lambda x: x * 2`, what is `f(5)`?
0
/ 5
Great job!

Quick-reference cheatsheet

Topic Stumbling Block Quick Answer
is vs == When to use each? == compares values; is compares identity (memory). Use is only for None, True, False.
List vs Tuple Which is which? List `[1, 2]` is mutable. Tuple `(1, 2)` is immutable and hashable (can be dict key).
Mutable defaults Why do defaults persist? Defaults evaluated at definition time, not call time. Use None and check inside.
Closures in loops Why do lambdas all return the same value? Lambdas capture variables, not values. Use default args: lambda x=i: x.
GIL Does threading help? No, for CPU-bound work. Yes, for I/O-bound. For CPU, use multiprocessing.
*args / **kwargs Which is which? *args = positional (tuple). **kwargs = keyword (dict).
Generator vs List When to use each? Use generators for large datasets (memory efficient). Lists for everything in memory.
LEGB Scope How is scope resolved? Local → Enclosing → Global → Built-in. Use global or nonlocal to modify outer.
Exception chaining How to preserve context? raise NewError(...) from original_error. Shows root cause in traceback.
Context managers Why use `with`? Guarantees cleanup (__exit__) even if an error occurs. Example: with open(file).

Key takeaways

  • Variables are references, not boxes. Python uses object references, not memory locations like C.
  • Mutability matters. Lists are mutable; tuples, strings, ints are not. This shapes how they behave in functions.
  • Closures capture variables, not values. Lambdas and nested functions bind to the variable itself, so changes propagate.
  • Clarity over cleverness. In interviews, explain tradeoffs. "A list is faster here, but a set is O(1) lookup—I'd choose set for this use case."
  • Know your context managers. Files, locks, database connections—always use with. Cleanup is guaranteed.
  • Generators save memory. For Razorpay or SouthBank processing millions of transactions, generators are the difference between running and crashing.
  • Scope is LEGB. Ask "which scope is this variable in?" when debugging weird behavior.
Africa & India's Best AI Academy
🤖 AI-first 🎓 Placement Assistance

You've practised 30 questions.
Now get a real mock interview.

Join the Best AI Program: The AI-Era Analyst — 5 months, fully online, with placement assistance. Week 1 is free.

Explore The AI-Era Analyst →