Mock interview 1: Python basics and an easy problem
60 min · Advanced
Need help? Ask a tutor on WhatsApp (opens in a new tab)A first round checks that your basics hold up under follow-up questions. This mock gives you the questions, the model answers and the easy problem, so you can practise aloud.
How a first round runs
A mock interview is a practice interview with a fixed script, a timer and a score sheet, so you can find weak answers before the real one.
A first round is usually 40 minutes: a short introduction, Python basics, one easy problem and your questions. Run this one with a friend or a timer. Cover the model answer, say yours aloud, then compare.
Example 1 · The 40-minute script
00-05 INTRO "Tell me about yourself": 60 seconds, one project05-20 BASICS 5 short questions, 2-3 minutes each20-35 PROBLEM one easy problem: clarify, idea, code, test35-40 YOUR Q two good questions for the interviewer5 + 15 + 15 + 5 = 40 minutes
What this code does
- The basics block has the most questions, so keep each answer short.
- The problem block is judged on talking and testing as much as on the final code.
Example 1 shows the minutes. Basics carry the most weight because a wrong answer here ends many interviews early.
Basics questions: what a strong answer sounds like
A model answer is a short, correct reply with three parts: a definition in one sentence, one small example, and one trap or use.
Interviewers ask about mutability, is versus ==, truthiness and default arguments, because each one shows if you understand how Python really holds values. Examples 2 to 4 give the script for each question.
Example 2 · Q1: mutable and immutable
prices = [10, 20]alias = pricesalias.append(30)print(prices)
name = "mentor"upper = name.upper()print(name, upper)[10, 20, 30] mentor MENTOR
What this code does
- A list is mutable:
aliasis the same list, so the change shows inprices. - A string is immutable:
upper()returns a new string andnamestays the same. - Model answer: "A mutable object changes in place, like a list. An immutable one cannot, like a string, a tuple or an int. Two names can point to one list, so a change through one shows in the other."
Example 3 · Q2 and Q3: is, == and truthiness
a = [1, 2]b = [1, 2]print(a == b, a is b)orders = []if not orders: print("no orders")print(bool(0), bool("0"), bool(None))True False no orders False True False
What this code does
==compares values.isasks if both names point to the same object.- An empty list, 0,
Noneand an empty string are false. The string "0" is true because it is not empty. - Model answer: "
==is equal values,isis same object. I useisonly forNone."
Example 4 · Q4: the default argument trap
def add_item(item, cart=[]): cart.append(item) return cart
print(add_item("pen"))print(add_item("book"))
def add_item_safe(item, cart=None): if cart is None: cart = [] cart.append(item) return cart
print(add_item_safe("pen"))print(add_item_safe("book"))['pen'] ['pen', 'book'] ['pen'] ['book']
What this code does
- The default list is created once, when
defruns, so every call shares it. - The safe version uses
Noneand makes a new list inside each call.
A strong answer is 20 to 30 seconds. A weak answer is a vague word like "it changes" with no example.
The easy problem: talk before you type
The interviewer says: find the first repeated order id in a list. Clarify, give an example, say the slow idea, improve it, then code and test it. Example 5 shows both ideas.
Example 5 · The easy problem: first repeated id
def first_repeat_slow(ids): for i in range(len(ids)): if ids[i] in ids[:i]: return ids[i] return None
def first_repeat(ids): seen = set() for order_id in ids: if order_id in seen: return order_id seen.add(order_id) return None
data = [7, 3, 9, 3, 7]print(first_repeat_slow(data), first_repeat(data))3 3
What this code does
- The slow idea checks the earlier part for every id: time grows with the square of the list size.
- The set idea remembers ids already seen. Looking up a set is quick, so one pass is enough: time O(n), extra space O(n).
- Say both aloud: "Brute force first, then I trade memory for speed."
Example 6 · Edge cases before you say done
def first_repeat(ids): seen = set() for order_id in ids: if order_id in seen: return order_id seen.add(order_id) return None
print(first_repeat([]))print(first_repeat([5]))print(first_repeat([1, 2, 3]))print(first_repeat([4, 4]))None None None 4
What this code does
- Empty list, one item and no repeat all give
None. Two equal items give the id. - Naming these tests aloud earns marks even if your code is correct.
Say the time cost of each idea aloud. Example 6 lists the edge cases to test before you say "done".
Scoring the round
After the round, give each part 0 to 4 and note one fix. Example 7 compares a strong and a weak reply to the same question so you can hear the difference.
Example 7 · A strong and a weak reply
Question: "What is the difference between a list and a tuple?"Weak: "A list uses square brackets and a tuple uses round ones."Strong: "A list is mutable, so I can add or change items. A tuple is immutable, so it is safe as a dictionary key and signals data that must not change, like an (x, y) point. Both keep order."Weak: 5 seconds, no idea shown. Strong: 20 seconds, definition + use + reason.
What this code does
- The weak reply describes the look, not the idea.
- The strong reply has a definition, a use and a link to hashing.
Repeat the round after two days. The score should rise because you now speak in the same short shape every time.
Next step
Check your understanding
10 quick questions