Python interview questions test your knowledge of data structures, mutability, list comprehensions, decorators, generators, and the Python standard library. Python shows up in backend, data, and automation roles alike, so interviewers look for clean, idiomatic code as much as correct answers. This page covers 40 real Python interview questions with answers across four formats: multiple choice, written answers, spoken responses, and live coding challenges, the same mix used in modern technical interviews.
Practice each question in your browser with no signup required. Answers stay hidden until you attempt the question: type, speak, or code your response first, then compare it against the model answer. Questions range from fundamentals for your first developer job to scenario-based questions for senior roles, so you can find the gaps in your knowledge before the real interview.
40 questions with answersLast updated: Oct 19, 2026
Choose a question. Pick any of the 40 questions. They mix multiple choice, written, spoken, and coding, the same mix a real interviewer uses.
Attempt your answer. Select a multiple-choice option, type your written response, record a spoken answer, or write code in the editor.
Reveal the model answer. Once you have attempted the question, the model answer unlocks so you can compare it with yours.
Move to the next question. Track how many questions you have attempted with the progress bar at the top of the page.
Take a mock interview. When you are ready, try a full mock technical interview on Plaicer with AI-driven follow-up questions.
Python Interview Questions and Answers
0 of 40 attempted
1Multiple choice
How would you characterize Python's approach to variable typing?
Attempt the question first to reveal the answer.
Answer
Python is dynamically typed. The interpreter assigns types based on what you assign to a variable at runtime, not through declarations.
2Written answer
Describe the key differences between lists and tuples, including when each is appropriate to use
Attempt the question first to reveal the answer.
Answer
Lists are mutable sequences using square brackets [1, 2, 3] where you can add, remove, or modify elements. Tuples are immutable sequences using parentheses (1, 2, 3) where contents cannot change after creation. Use lists for collections that grow or shrink over time. Use tuples for fixed data like coordinates or database records. Tuples can serve as dictionary keys because they're hashable; lists cannot.
3Spoken answer
Walk through how you would debug a Python function that's returning incorrect results
This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.
Attempt the question first to reveal the answer.
Answer
I'd start by adding print statements at key points to trace variable values and execution flow. For more systematic debugging, I'd use pdb by inserting 'import pdb; pdb.set_trace()' to step through code line by line. I'd check assumptions about input data first, then verify each calculation. If dealing with multiple calls, I'd isolate the failing case. For production code, I'd use the logging module instead of print statements to avoid leaving debug code.
4Coding
Write a function that reverses a string without using built-in reverse methods
def reverse_string(text):
# Your implementation here
pass
Attempt the question first to reveal the answer.
Answer
def reverse_string(text):
return text[::-1]
# Or using a loop:
def reverse_string_loop(text):
result = ''
for char in text:
result = char + result
return result
5Multiple choice
Given nums = [10, 20, 30]; ref = nums; nums.append(40); what does ref contain?
Attempt the question first to reveal the answer.
Answer
ref = nums creates a reference to the same list, not a copy. When you append to nums, ref reflects the change because both point to the same object.
6Written answer
Explain Python's argument passing mechanism and the implications for mutable versus immutable objects
Attempt the question first to reveal the answer.
Answer
Python uses call-by-object-reference: you pass a reference to the object, not a copy. For mutable objects like lists, modifications inside the function affect the original. For immutable types like integers and strings, reassigning the parameter only affects the local variable. Example: appending to a list parameter changes the caller's list, but reassigning the parameter name does not.
7Spoken answer
Explain a situation where you used list comprehension in real code and why it was better than the alternative
This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.
Attempt the question first to reveal the answer.
Answer
I once needed to filter temperature readings above a threshold and convert them from Celsius to Fahrenheit in one step. Using comprehension: [c * 9/5 + 32 for c in readings if c > threshold] was much cleaner than a traditional loop that would need append calls. It was more readable for other developers and ran slightly faster. The intent was immediately clear from one line rather than four.
8Coding
Given a list of user ID numbers, identify which IDs appear more than once in the dataset
def find_duplicate_ids(user_ids):
# Your implementation here
pass
# Example usage:
ids = [101, 202, 101, 303, 202, 404]
# Should return [101, 202]
Attempt the question first to reveal the answer.
Answer
def find_duplicate_ids(user_ids):
from collections import Counter
counts = Counter(user_ids)
return [uid for uid, count in counts.items() if count > 1]
# Or using a set:
def find_duplicate_ids_alt(user_ids):
seen = set()
duplicates = set()
for uid in user_ids:
if uid in seen:
duplicates.add(uid)
seen.add(uid)
return list(duplicates)
9Multiple choice
Which data structure cannot be modified after creation?
Attempt the question first to reveal the answer.
Answer
Tuples are immutable sequences. Once created, their contents cannot be changed. Lists, dictionaries, and sets are all mutable.
10Written answer
What are decorators in Python and provide an example of how they extend function behavior without modifying the original code
Attempt the question first to reveal the answer.
Answer
Decorators are functions that wrap other functions to add functionality. A decorator takes a function as input, adds behavior, and returns an enhanced version. Applied with the @ symbol. Common uses include logging, timing, authentication, and caching. Example: @timer decorator could measure execution time by recording start time before calling the function and elapsed time after.
11Spoken answer
Describe how you'd explain the concept of mutability to a junior developer who's confused about list behavior
This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.
Attempt the question first to reveal the answer.
Answer
I'd start with a concrete example: show them creating two lists and assigning one to the other, then modifying the original and observing the assigned copy changes too. I'd explain it's like having two name tags pointing to the same object in memory. Then I'd contrast with strings by showing that reassigning a string doesn't affect other references. The key insight is that mutable objects are modified in place, while immutable objects require creating new objects.
12Coding
Given a nested structure of customer orders where orders contain line items, flatten it into a single list of all line items
def flatten_orders(orders_structure):
# Your implementation here
pass
# Example:
orders = [['item1', 'item2'], ['item3', ['item4', 'item5']]]
# Should return ['item1', 'item2', 'item3', 'item4', 'item5']
Attempt the question first to reveal the answer.
Answer
def flatten_orders(orders_structure):
result = []
for item in orders_structure:
if isinstance(item, list):
result.extend(flatten_orders(item))
else:
result.append(item)
return result
13Multiple choice
What operation does the // symbol perform on integers?
Attempt the question first to reveal the answer.
Answer
The // operator performs floor division. 5//2 returns 2, not 2.5.
14Written answer
Define mutability in Python and categorize common data types as mutable or immutable
Attempt the question first to reveal the answer.
Answer
Mutable types can change after creation with modifications happening in-place. Examples: lists, dictionaries, sets. Immutable types cannot change; modifications create new objects. Examples: strings, tuples, integers, floats, frozensets. This distinction matters for performance (in-place is faster) and functionality (immutable types can be dictionary keys).
15Spoken answer
How would you approach optimizing code that processes a large dataset and runs slowly
This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.
Attempt the question first to reveal the answer.
Answer
First, I'd profile the code to identify the actual bottleneck rather than guessing. I'd use the timeit module or cProfile to measure which functions consume the most time. Common optimizations include using list comprehensions instead of loops, replacing nested loops with dictionaries for lookups, or using generator expressions for memory efficiency. I'd also consider algorithmic improvements like avoiding redundant calculations or using better data structures for the access patterns.
16Coding
Given a list of prices and a target total, find two prices that add up to the target. Return their indices
def find_matching_prices(prices, target):
# Your implementation here
pass
# Example:
prices = [25, 50, 75, 100]
target = 125
# Should return [1, 2] (indices where 50 + 75 = 125)
Attempt the question first to reveal the answer.
Answer
def find_matching_prices(prices, target):
seen = {}
for i, price in enumerate(prices):
complement = target - price
if complement in seen:
return [seen[complement], i]
seen[price] = i
return None
17Multiple choice
Using negative indexing, how would you retrieve the third item from the end of a list?
Attempt the question first to reveal the answer.
Answer
Negative indexing starts from the end. -1 is the last element, -2 is second-to-last, and -3 is third-to-last.
18Written answer
Explain the role of context managers in resource management and why they're important
Attempt the question first to reveal the answer.
Answer
Context managers automatically handle setup and cleanup of resources like files and network connections. The 'with' statement calls __enter__ when entering the block and guarantees __exit__ runs when leaving, even if exceptions occur. This prevents resource leaks and is cleaner than manual try/finally patterns. Example: 'with open(file) as f:' automatically closes the file.
19Spoken answer
Explain the difference between module-level scope and local scope with a practical example
This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.
Attempt the question first to reveal the answer.
Answer
Module-level scope contains variables defined at the top of a file, accessible throughout. Local scope is inside a function, accessible only there. If a function modifies a module-level variable, it needs the 'global' keyword. Example: a counter variable at module level could track how many times a function was called, but only if the function declares it global. Without that, it would create a local variable instead.
20Coding
Generate the first n numbers in the Fibonacci sequence where each number equals the sum of the two preceding values
def generate_fibonacci(n):
# Your implementation here
pass
# Example:
# generate_fibonacci(6) should return [0, 1, 1, 2, 3, 5]
Attempt the question first to reveal the answer.
Answer
def generate_fibonacci(n):
if n <= 0:
return []
if n == 1:
return [0]
fib = [0, 1]
for i in range(2, n):
fib.append(fib[i-1] + fib[i-2])
return fib[:n]
21Multiple choice
What boolean value does an empty list evaluate to?
Attempt the question first to reveal the answer.
Answer
Empty collections evaluate to False in boolean context. Non-empty collections evaluate to True.
22Written answer
Compare shallow and deep copying methods and explain when each should be used
Attempt the question first to reveal the answer.
Answer
Shallow copy creates a new object but inserts references to nested objects from the original. Changes to nested structures affect both copies. Deep copy creates a completely independent clone with all nested objects duplicated. Use shallow copy for flat structures with immutable elements. Use deep copy for nested structures with mutable elements to ensure true independence.
23Spoken answer
How would you handle errors in a function that reads data from an external API
This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.
Attempt the question first to reveal the answer.
Answer
I'd wrap the API call in try/except to catch specific exceptions like ConnectionError or TimeoutError separately from unexpected errors. I'd retry failed requests with exponential backoff to handle temporary failures gracefully. I'd log errors for debugging while returning user-friendly messages. I'd also validate the response structure before processing to catch malformed data. For production code, I'd use a retry library to avoid reinventing this logic.
24Coding
Determine if a product SKU string is a valid palindrome (ignoring spaces, dashes, and case)
def is_valid_sku(sku):
# Your implementation here
pass
# Examples:
# is_valid_sku('A1B-2-B1A') should return True
# is_valid_sku('SKU-1234') should return False
Attempt the question first to reveal the answer.
Answer
def is_valid_sku(sku):
cleaned = ''.join(char.lower() for char in sku if char.isalnum())
return cleaned == cleaned[::-1]
25Multiple choice
What keyword brings external modules into your program?
Attempt the question first to reveal the answer.
Answer
Python uses the 'import' keyword to load modules with syntax like 'import module_name' or 'from module_name import function_name'.
26Written answer
Describe the variable lookup order Python follows when resolving names through the LEGB rule
Attempt the question first to reveal the answer.
Answer
LEGB stands for Local, Enclosing, Global, Built-in. Python searches for a variable in this order: Local (inside current function), Enclosing (in outer functions), Global (module level), Built-in (like print, len). This explains why accessing global variables requires the 'global' keyword and why nested functions can access outer function variables.
27Spoken answer
Describe how you'd design a class to represent a bank account with proper encapsulation
This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.
Attempt the question first to reveal the answer.
Answer
I'd make the balance a private attribute with the __ prefix to prevent direct modification. I'd provide public methods like deposit() and withdraw() that validate inputs and maintain invariants like preventing negative balances. I'd add a getter for reading balance without modification. This enforces business rules in one place and prevents accidental data corruption. I might also add logging to track all balance changes for auditing.
28Coding
Merge two sorted lists of invoice amounts into a single sorted list without using built-in sort
def merge_invoice_lists(list1, list2):
# Your implementation here
pass
# Example:
# merge_invoice_lists([10, 30, 50], [15, 25, 40])
# Should return [10, 15, 25, 30, 40, 50]
Attempt the question first to reveal the answer.
Answer
def merge_invoice_lists(list1, list2):
result = []
i, j = 0, 0
while i < len(list1) and j < len(list2):
if list1[i] <= list2[j]:
result.append(list1[i])
i += 1
else:
result.append(list2[j])
j += 1
result.extend(list1[i:])
result.extend(list2[j:])
return result
29Multiple choice
When you use zip([1,2], ['x','y']), what structure is created?
Attempt the question first to reveal the answer.
Answer
zip() pairs elements from multiple iterables by index, returning an iterator of tuples.
30Written answer
What is list comprehension and what advantages does it offer over traditional iteration with loops
Attempt the question first to reveal the answer.
Answer
List comprehension creates lists using concise syntax: [expression for item in iterable if condition]. Instead of explicit loops with append(), it expresses intent in one readable line. Advantages include better readability, faster execution due to optimized C-level implementation, and cleaner code. Example: [x**2 for x in range(10) if x % 2 == 0] replaces a 4-line loop.
31Spoken answer
What approach would you take to write reusable code across multiple projects
This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.
Attempt the question first to reveal the answer.
Answer
I'd identify common patterns and extract them into utility functions or classes that don't depend on project-specific details. I'd document them well with docstrings and type hints for clarity. I'd consider creating a shared module or package that multiple projects import, versioning it appropriately. I'd write comprehensive tests to ensure reliability. For functions, I'd make them general-purpose with parameters for customization rather than hardcoding values.
32Coding
Given a log of transaction descriptions, count how many times each keyword appears (case-insensitive)
def count_keywords(descriptions):
# Your implementation here
pass
# Example:
# count_keywords('purchase sale Purchase refund Sale')
# Should return {'purchase': 2, 'sale': 2, 'refund': 1}
Attempt the question first to reveal the answer.
Answer
def count_keywords(descriptions):
from collections import Counter
words = descriptions.lower().split()
return dict(Counter(words))
33Multiple choice
In Python, what is the purpose of the pass keyword?
Attempt the question first to reveal the answer.
Answer
pass is a no-op statement used when syntax requires a statement but you don't want to execute anything. Commonly used in empty function definitions.
34Written answer
Distinguish between value equality and identity comparison in Python using == and is operators
Attempt the question first to reveal the answer.
Answer
The == operator checks if two objects have the same value (equality). The 'is' operator checks if they refer to the same object in memory (identity). Use 'is' when checking for None, True, False. Most comparisons use ==. A common mistake: using 'is' with numbers or strings where Python caches certain values, making 'is' appear to work unpredictably.
35Spoken answer
Explain how generators help with memory efficiency and when you'd use them instead of lists
This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.
Attempt the question first to reveal the answer.
Answer
Generators produce values one at a time using yield instead of creating everything in memory. For processing large files or data streams, generators consume minimal memory since only one item is in memory at a time. They're ideal for creating data pipelines where later stages process output from earlier stages. You'd use generators for potentially infinite sequences like sensor readings, whereas you'd use lists for small, fixed collections you need random access to.
36Coding
Remove all duplicate employee IDs from a list while preserving the original order of first occurrence
def remove_duplicate_employees(employee_ids):
# Your implementation here
pass
# Example:
# remove_duplicate_employees([1001, 1002, 1001, 1003, 1002])
# Should return [1001, 1002, 1003]
Attempt the question first to reveal the answer.
Answer
def remove_duplicate_employees(employee_ids):
seen = set()
result = []
for emp_id in employee_ids:
if emp_id not in seen:
result.append(emp_id)
seen.add(emp_id)
return result
37Multiple choice
What is the safest way to verify a key is present in a dictionary?
Attempt the question first to reveal the answer.
Answer
Use the 'in' operator to check for key existence. dict[key] would raise KeyError if missing. get() is useful when you want a default value.
38Written answer
What does self signify in instance methods and why must it be included as the first parameter
Attempt the question first to reveal the answer.
Answer
self is a convention for the first parameter in instance methods, referring to the instance the method is called on. Unlike languages where instance reference is implicit, Python makes it explicit. When you call dog.bark(), Python automatically passes dog as self. While technically any name works, using 'self' is universal convention. Forgetting it causes TypeError when calling methods.
39Spoken answer
How would you approach learning and teaching a new Python feature or library to your team
This browser cannot record audio. Answer the question out loud anyway, then compare yourself against the model answer below.
Attempt the question first to reveal the answer.
Answer
I'd start by exploring the documentation and writing small test examples to understand it deeply. Then I'd create a brief presentation with practical examples relevant to our codebase, not abstract demos. I'd prepare sample code they could run immediately and point out gotchas I discovered. I'd encourage questions and create follow-up resources. I'd lead a code review session applying it to real work so the team sees the value immediately rather than just learning theory.
40Coding
Write a function to transpose a database table (swap rows and columns)
def transpose_table(table):
return [list(row) for row in zip(*table)]
# Or using list comprehension:
def transpose_table_alt(table):
if not table:
return []
return [[table[i][j] for i in range(len(table))] for j in range(len(table[0]))]
How many Python interview questions are on this page?
40 real Python interview questions across four formats: multiple choice (10), written answer (10), spoken answer (10), and coding (10).
Do I need to sign up to practice?
No. All 40 questions and model answers are free with no signup. You attempt each question first, and the model answer unlocks once you have engaged.
Who are these Python interview questions for?
Developers preparing for Python technical interviews at any level, from first job to senior engineer roles. Questions cover fundamentals through real-world scenarios.
What topics do the Python questions cover?
The questions cover core Python concepts, built-in data structures, and mutability. They also test scope, comprehensions, decorators, context managers, and generators. Coding tasks cover strings, duplicates, merging, and other common interview problems.
Can I practice coding questions in the browser?
Yes. Coding questions include starter code in an in-browser editor, so you can write your solution without installing anything.
How often are the questions updated?
The question bank is reviewed regularly and updated to reflect current Python interview patterns.
Can I take a full mock interview?
Yes. Plaicer's mock technical interview walks you through a realistic 30 to 45 minute interview with AI-driven follow-up questions.
Which Python version do the questions cover?
Python 3. Every question and model answer uses current Python 3 syntax and behavior.