Data types & mutability
List vs tuple vs set - when do you use each?
A list is ordered and mutable; a tuple is ordered and immutable (so it can be a dict key or set element); a set is unordered with unique elements and fast membership tests. Choose by whether you need order, mutability, or uniqueness.
Mutable vs immutable types, and why does it matter?
Ints, floats, strings and tuples are immutable; lists, dicts and sets are mutable. It matters because passing a mutable object to a function lets that function modify the caller's data in place.
'is' vs '=='?
'==' compares values (equality); 'is' compares identity (whether two names point to the same object in memory). Use '==' for value checks and 'is' only for singletons like None.
What backs a Python dictionary?
A hash table. Keys must be hashable (immutable), which is why lists can't be keys but tuples can. Lookups are O(1) on average.
Pythonic features interviewers love
What is a list/dict/set comprehension?
A concise expression that builds a collection in one line, e.g. [x*x for x in nums if x > 0]. It's usually faster and clearer than an equivalent manual loop.
What are *args and **kwargs, and what's the mutable-default trap?
*args captures extra positional arguments as a tuple; **kwargs captures extra keyword arguments as a dict. The trap: a default like def f(x=[]) reuses the same list across calls - use x=None and create the list inside the function.
What is a decorator?
A function that wraps another function to add behaviour - logging, timing, access control - without changing its code. You apply it with the @decorator syntax above the function.
What are generators and the yield keyword?
Generators produce values lazily, one at a time, using yield instead of return. They keep memory flat for large or infinite sequences because they don't build the whole result in memory.
OOP & the standard library
Explain self, __init__, and instance vs class variables.
__init__ initialises a new instance; self refers to that instance. Instance variables are unique per object; class variables are shared across all instances of the class.
How does inheritance and the MRO work?
Python supports multiple inheritance, and the method resolution order (MRO, via the C3 algorithm) determines which parent's method is used. Dunder methods like __str__ and __len__ let your objects work with built-ins.
Shallow copy vs deep copy?
A shallow copy duplicates the outer object but shares references to nested objects; a deep copy (copy.deepcopy) duplicates everything recursively. It matters when your object contains other mutable objects.
NumPy and Pandas basics for data roles?
NumPy arrays are fast, typed, vectorised alternatives to Python lists for numeric work. Pandas DataFrames are labelled, table-like structures for loading, cleaning and analysing data.
How to actually get ready
Recognising these questions isn't the same as answering them under pressure. Drill them as timed MCQs, read the explanation for anything you miss, and revisit weak spots the next day. For data roles, interleave Python with SQL and ML-concept practice.
One habit that pays off fast: whenever you learn a concept, write a three-line snippet that demonstrates it - a decorator, a generator, a comprehension. Being able to produce a tiny working example is exactly what turns a hesitant answer into a confident one.
Practice this now
