Skip to content

Expert · Python in the real world · topic 50 of 50 · 30 min

Python interview preparation

Explanation

Python interviews usually have an online test, a coding round, a technical discussion and an HR round. Practise classic problems (palindromes, FizzBuzz, two-sum), learn short clear answers to common theory questions, and always explain your thinking out loud.

How the process usually works

  1. Online test: MCQs on Python output and logic, plus one or two coding problems with a timer.
  2. Coding round: you solve a problem while an interviewer watches, on a shared editor or paper.
  3. Technical round: questions about Python concepts and your projects.
  4. HR round: your background, why this company, notice period and salary expectations.
Think of it like this: A coding interview is like a driving test. The examiner cares less about reaching the destination fast and more about whether you check mirrors, signal and stay calm. Explaining your steps is your "checking mirrors".

A method for every coding question

  1. Repeat the problem in your own words and ask about edge cases (empty list? negative numbers?).
  2. Work one small example by hand.
  3. Say a simple solution first, even if slow, and its big-O.
  4. Improve it if you can (often with a set or dict).
  5. Write clean code with good names, then test it with your example and an edge case.

Classic problem: two-sum

Given a list of numbers and a target, find the positions of two numbers that add up to the target. The slow way checks every pair (O(n²)). The fast way remembers numbers already seen in a dict (O(n)).

python
def two_sum(nums, target):
    seen = {}  # number -> index
    for i, n in enumerate(nums):
        need = target - n
        if need in seen:
            return (seen[need], i)
        seen[n] = i
    return None

print(two_sum([2, 7, 11, 15], 9))
One pass with a dict. Shows (0, 1).

Theory questions with short answers

QuestionShort answer
List vs tuple?A list can change (mutable); a tuple cannot (immutable). Tuples suit fixed records and can be dict keys.
is vs ==?== compares values; is checks whether two names point to the very same object.
Shallow vs deep copy?A shallow copy copies the outer list only; inner lists are shared. copy.deepcopy copies everything.
*args and **kwargs?args collects extra positional arguments as a tuple; kwargs collects extra keyword arguments as a dict.
What is a generator?A function with yield that produces values one at a time, saving memory.
What is a decorator?A function that wraps another function to add behaviour, written with @.
What is the GIL?The Global Interpreter Lock lets only one thread run Python code at a time in standard CPython, so threads help with waiting (network, files) more than with heavy maths.
python
a = [[1, 2], [3, 4]]
b = a.copy()        # shallow
b[0].append(99)
print(a)            # [[1, 2, 99], [3, 4]] - inner list is shared
print([1] == [1], [1] is [1])
A favourite interview trap: shallow copy, and == versus is.
Tip: Practise "predict the output" questions. Write a small snippet, guess what it prints, then run it. This trains you for MCQ online tests.
Careful: Do not stay silent for minutes in a coding round. If you are stuck, say what you are thinking and what you have tried. Interviewers often give hints to candidates who talk.

Talk about your projects

Be ready to explain one project in two minutes: the problem, what you built, one hard bug you fixed and what you would improve. The projects from this course (grade calculator, expense tracker, quiz, password checker) are good starting points; extend one and put it on GitHub.

Watch the lesson

Python interview preparation · 1/7

Interview preparation

This lesson prepares you for Python job interviews, from the online test to the HR round.

Prefer a video by a teacher? Find free videos on “python interview questions and answers for freshers” on YouTube ↗

In real life: A campus placement coding round

In a campus drive, Karthik gets the question "find two numbers in a list that add up to a target". He first explains the simple double loop and says it is O(n²). Then he suggests a dict to remember numbers he has seen, writes it, and tests it with an empty list too. Even though another candidate typed faster, Karthik is selected because his thinking was clear.

python
def is_palindrome(text):
    clean = text.replace(" ", "").lower()
    return clean == clean[::-1]

print(is_palindrome("Never odd or even"))
Another common question: is a phrase a palindrome?

Practice (0/3 done)

Task 1 · Code · Python

Write a function is_palindrome(text) that returns True if text reads the same forwards and backwards, ignoring spaces and capital letters. "Never odd or even" is a palindrome.

Task 2 · Code · Python

FizzBuzz: write a function fizzbuzz(n) that returns a list of strings for the numbers 1 to n. Use "Fizz" for multiples of 3, "Buzz" for multiples of 5, "FizzBuzz" for multiples of both, and the number itself (as a string) otherwise.

Task 3 · Code · Python

Write a function two_sum(nums, target) that returns a pair (i, j) with i < j where nums[i] + nums[j] == target, or None if there is no such pair. Try to use a dict so the list is read only once.

Quick quiz

Question 1

1.What is the difference between == and is?

Question 2

2.What is the big-O of two-sum using a dict of seen numbers?

Question 3

3.After b = a.copy() where a = [[1], [2]], what does b[0].append(5) do to a?

Question 4

4.What should you do first when given a coding question?

Question 5

5.Which is the best one-line description of a decorator?

Read more (free)

Pass the quiz (60% or more) or mark this topic as done when you are ready.

Your progress is saved on this device only.

← Previous: What Python is used for: web, data and AI