Frequently asked Python interview questions with concise answers — data types, comprehensions, functions and pandas basics. Practise them in a free AI mock interview.
Practise these in a free AI mock interviewLists are mutable and use []; tuples are immutable and use (). Use tuples for fixed collections and as dictionary keys, and lists for data that changes.
An insertion-ordered collection of key-value pairs with fast lookups by key, written {}. Keys must be unique and hashable.
A concise way to build a list: [x*x for x in range(5)] gives [0, 1, 4, 9, 16]. It is more readable and often faster than a for-loop with append.
== compares values (are they equal?); is compares identity (the same object in memory?). Use == for value checks and is mainly for None.
*args collects extra positional arguments into a tuple; **kwargs collects extra keyword arguments into a dict. They let a function accept a variable number of arguments.
A small anonymous function, e.g. square = lambda x: x*x. Handy for short throwaway functions such as a key in sorted().
append(x) adds x as one element; extend(iterable) adds each element of the iterable. [1,2].append([3,4]) gives [1,2,[3,4]]; extend gives [1,2,3,4].
A function that wraps another to add behaviour (logging, timing, auth) without changing its code, applied with @decorator syntax.
Through reference counting plus a cyclic garbage collector that frees objects no longer referenced. You usually do not manage memory manually.
A Series is a 1D labelled array (like a column); a DataFrame is a 2D labelled table of rows and columns. They are the core structures for data analysis in pandas.
A shallow copy copies the outer object but shares the nested objects; a deep copy (copy.deepcopy) duplicates everything. Changing a nested item in a shallow copy also changes the original.
A function using yield that produces values one at a time on demand instead of building a whole list in memory — efficient for large or streaming data.
A module is a single .py file; a package is a directory of modules (with an __init__.py). Packages organise larger codebases into namespaces.
An unordered collection of unique items. Use it to remove duplicates or to do fast membership tests and set operations like union and intersection.
A lock that lets only one thread run Python bytecode at a time, which limits CPU-bound threading. Use multiprocessing for CPU work, or async and threads for I/O-bound work.
range is a lazy sequence that generates numbers on demand and uses almost no memory; a list stores all its values. Iterating range(1_000_000) does not build a million-element list.
Immutable types (int, str, tuple, frozenset) cannot change after creation; mutable types (list, dict, set) can. Mutability affects copying, default arguments and what can be a dictionary key.
Use try/except, optionally with else and finally. Catch specific exceptions rather than a bare except, use finally for cleanup, and re-raise with raise when you cannot handle the error.
An object that sets up and cleans up a resource automatically. with open(path) as f: closes the file even if an error occurs, which prevents resource leaks.
It runs the code below it only when the file is executed directly, not when it is imported as a module — handy for files that are both importable and runnable.
df = pd.read_csv("file.csv"), then df.head() to preview, df.info() for types and nulls, and df.describe() for summary statistics of the numeric columns.
map works element-wise on a Series, apply works on a Series or along a DataFrame axis, and applymap works element-wise across an entire DataFrame.
Taking part of a sequence with [start:stop:step]. a[1:4] returns elements 1 to 3, a[::-1] reverses the list, and a[:3] takes the first three.
remove(value) deletes the first matching value, pop(index) removes and returns the item at an index (the last by default), and del removes by index or slice without returning anything.
An isolated folder with its own Python and packages so each project has independent dependencies. Create it with python -m venv .venv and activate it before installing packages.
Knowing the answers isn’t enough — say them out loud
Practise these Python questions in a free AI mock interview: answer by voice, get instant feedback on your strengths and the gaps to fix.
Admissions open · free to apply
Attended a masterclass or have a friend's referral code? You get ₹15,000 off. Fill this and our team takes it from here — pay by cash or online.