5 interview questions: answer them like a developer

Watch the interviewer ask each question, see a strong answer built in three parts, and keep one memory point for each.

1

Question 1

How to explain this answer ↓

How to explain each answer in the interview

Every answer has the same three parts: start with one clear line, give one example, and finish with the reason. Read each part aloud. Click a question to watch it again above.

Say it like this

  1. 1 Start“Before I write any code, I answer three questions. What data do I have? What must happen to it? And how should I pack the code: as a function or as a class?”
  2. 2 Example“For example, if I am asked for the total of today’s paid orders, the data is a list of orders, each with a status and an amount. The operation is to go through them, keep the paid ones and add the amounts. It is one task, so I write one function.”
  3. 3 Finish“It takes a minute, and it saves me from writing code that I later have to throw away.”

Spoken at a normal pace, this takes about 40 seconds. Stop there, and let the interviewer ask for more.

Avoid saying

"I just start coding and fix things as I go." It tells the interviewer that you have no method.

Likely next question

What if the task is very large? I break it into smaller tasks and ask the same three questions for each one.

🧠 Memory points

Have, Do, Pack

  • Have: the data. Where it comes from, one value or many, and its type.
  • Do: the operation. Calculate, compare, combine, check or repeat.
  • Pack: the design. A function or a class.

Picture it: Packing for a trip: what do I have, what will I do there, and which bag do I pack it in?

If you are asked to show it on paper

QuestionWhat I decideFor "total of paid orders"
1. What do I have?The dataA list of orders
2. What do I do with it?The operationRepeat, compare, calculate
3. How do I pack it?The designOne function

Say it like this

  1. 1 Start“I think of them in two groups. For one value there are int, float, str and bool. For many values there are list, tuple, set and dictionary.”
  2. 2 Example“In an online shop, a quantity is an int, a price is a float, a customer’s name is a str, and "is it paid?" is a bool. The items in a cart are a list, and one order with its ID and amount is a dictionary.”
  3. 3 Finish“To choose, I ask four things: is it one value or many, does the order matter, will it change, and do I need to look things up by a name?”

Spoken at a normal pace, this takes about 40 seconds. Stop there, and let the interviewer ask for more.

Avoid saying

Reciting eight names in one breath and stopping. The question has a second half: how you choose. Most candidates forget to answer it.

Likely next question

When would you use a tuple and not a list? A list when the values will change; a tuple when they must stay fixed, such as a pair of map coordinates.

🧠 Memory points

4 singles, 4 groups

  • Singles: int, float, str, bool.
  • Groups: list, tuple, set, dict.
  • A list changes, a tuple is fixed, a set has no repeats, a dict has labels.

Picture it: A tiffin carrier: some things are single items, and some are boxes that hold many items.

If you are asked to show it on paper

TypeHoldsExampleThink of it as
intA whole number2Counting
floatA decimal number149.50Measuring
strText"Ravi"Words
boolTrue or FalseTrueYes or no
listMany values, in order, can change["pen", "book"]A shopping list
tupleMany values, in order, fixed(17.38, 78.48)A sealed pair
setUnique values, no order{"Pune", "Chennai"}No repeats
dictNames paired with values{"id": 101, "amount": 300}A labelled form

Say it like this

  1. 1 Start“A function is a named block of code that does one task. Data goes in through its parameters, and the result comes out with return.”
  2. 2 Example“Say a shop adds GST to prices on the product page, in the cart and on the invoice. I write the calculation once, as a function, and call it from all three places.”
  3. 3 Finish“So functions remove repeated code, each one can be tested alone, and when the rule changes I change it in one place.”

Spoken at a normal pace, this takes about 40 seconds. Stop there, and let the interviewer ask for more.

Avoid saying

"A function is something that prints the output." It mixes up print and return, and that is usually the very next question.

Likely next question

What is the difference between print and return? print shows a value on the screen. return hands it back to the code that called the function, so that it can be stored and used.

🧠 Memory points

In, work, out

  • def gives it a name.
  • Parameters bring the data in.
  • return hands the result out.
  • It remembers nothing afterwards.

Picture it: A juicer: fruit goes in, juice comes out, and nothing stays inside.

If you are asked to write an example

def price_with_gst(price, rate=18):
    return price + price * rate / 100

print(price_with_gst(100))       # 118.0
print(price_with_gst(250))       # 295.0

Say it like this

  1. 1 Start“A class is a design for objects. An object keeps some data, and the functions that work on that data, together in one place.”
  2. 2 Example“Take a bank account. The balance is the data. Deposit and withdraw are its functions, which we call methods. __init__ runs once, when the account is created, and stores the starting balance. self is the object itself, so self.balance means this account’s own balance.”
  3. 3 Finish“Because each object has its own data, I can create a thousand accounts from one class, and their balances never mix.”

Spoken at a normal pace, this takes about 40 seconds. Stop there, and let the interviewer ask for more.

Avoid saying

"A class is like a bigger function." A function does one task and forgets. A class keeps data and offers several actions on it.

Likely next question

Is __init__ the constructor? People call it that. To be exact, Python creates the object first, and __init__ then fills in its starting data.

🧠 Memory points

Design, object, store, mine

  • class: the design, written once.
  • object: one thing built from the design.
  • __init__: stores the data, once.
  • self: mine, this object’s own data.

Picture it: A bank passbook: the bank prints one design, and every customer gets their own book with their own balance.

If you are asked to write an example

class Account:
    def __init__(self, balance):
        self.balance = balance           # stored once

    def deposit(self, amount):
        self.balance = self.balance + amount

ravi = Account(5000)                     # __init__ runs here
ravi.deposit(2000)
print(ravi.balance)                      # 7000

Say it like this

  1. 1 Start“My rule is simple. One task needs a function. Several tasks that work on the same data need a class.”
  2. 2 Example“Totalling paid orders is one task, so it is a function. A nightly sales report that loads a file, removes the refunds, totals by city and saves the result is four steps on the same orders, so it is a class with four methods.”
  3. 3 Finish“I always start with functions. When I see several functions passing the same data to each other, I move that data into a class.”

Spoken at a normal pace, this takes about 40 seconds. Stop there, and let the interviewer ask for more.

Avoid saying

"Classes are better because they are more professional." The design depends on the problem, not on looking advanced. Interviewers ask this to test your judgement.

Likely next question

What tells you that a function should become a class? The same three or four values being passed into many functions.

🧠 Memory points

One task: function. Shared data: class.

  • Count the tasks.
  • Look for data that several actions share, or that must be remembered.
  • Start with a function.
  • A class with one method is a function in disguise.

Picture it: One job needs one tool. A toolbox is for several tools that work on the same job.

If you are asked to write an example

# one task: a function
def paid_total(orders):
    return sum(o["amount"] for o in orders if o["status"] == "paid")

# several steps on the same orders: a class
class SalesReport:
    def __init__(self, orders):
        self.orders = orders             # stored once, shared by every step

    def clean(self):
        self.orders = [o for o in self.orders if o["status"] == "paid"]

    def total(self):
        return sum(o["amount"] for o in self.orders)

orders = [{"status": "paid", "amount": 300}, {"status": "refunded", "amount": 150},
          {"status": "paid", "amount": 200}]
report = SalesReport(orders)
report.clean()
print(report.total())                    # 500

🧠 Your memory card: all five on one page

Each hook is a short phrase that brings the whole answer back. Learn the hook and the first line; the rest follows.

The five hooks

QuestionHookFirst line to say
Q1You are given a new programming task. How do you start?Have, Do, Pack“Before I write any code, I answer three questions.”
Q2Which data types do you know in Python, and how do you choose one?4 singles, 4 groups“I think of them in two groups.”
Q3What is a function, and why do we use functions?In, work, out“A function is a named block of code that does one task.”
Q4What is a class? And what do __init__ and self mean?Design, object, store, mine“A class is a design for objects.”
Q5When would you use a class instead of a function?One task: function. Shared data: class.“One task needs a function; shared data needs a class.”

How to keep them for good

TodaySay all five answers aloud once, looking at the notes.
TomorrowCover the notes. Read only the hooks and say the answers.
After 3 daysAsk a friend to play the interviewer and time you: 40 seconds each.
After 7 daysAnswer all five with a new example of your own for each.

Three habits that make answers stick

  • Say it aloud. Reading feels like knowing, but only speaking shows whether you can produce the answer.
  • Teach it. Explain one answer to a friend or a family member; where you stumble is what to revise.
  • Keep the card close. Write the five hooks on one small card and read it while you wait for a bus or a class.