Data TrailhouseSign inJoin free
Menu
INTERVIEW PREP · FOR FRESHERS

Python interview questions for freshers

Python and pandas questions for fresh graduates applying to data roles, with clear answers and small code examples. 20 questions with answers, written by a Senior Data Engineer.

How to prepare in one week

  1. Know the basics cold. Freshers are judged on fundamentals: joins, grouping, data types, and why you would choose one approach over another.
  2. Practise out loud. Say each answer in under a minute, then give one small example. Interviewers remember examples, not definitions.
  3. Write code by hand. Solve a few problems without autocomplete. Our free practice editors check your answer instantly.
  4. Show one project. Prepare a 2 minute story about one project: the data, what you built, one problem you solved and the result.
  5. Do a mock interview. Our AI mock interview asks 8 questions for your role and scores each answer. The first one is free.
  6. Fix your resume and LinkedIn. Run the free ATS resume checker and LinkedIn optimizer against the job post before you apply.

The questions, with answers

01List vs tuple?

Lists are mutable, tuples are immutable. Tuples can be dictionary keys and are slightly faster.

02What is a dictionary and how is it implemented?

A key to value mapping built on a hash table, so lookups are O(1) on average. Keys must be hashable.

03What is the difference between == and is?

== compares values. is checks if two names point to the same object. Use is only for None.

04What are *args and **kwargs?

*args collects extra positional arguments into a tuple, **kwargs collects extra keyword arguments into a dict.

05What is a list comprehension?

A short way to build a list from a loop and an optional condition.

squares = [x * x for x in nums if x > 0]

06What is a generator?

A function that uses yield and produces values one at a time, so it uses little memory for large data.

def read_lines(path):
    with open(path) as f:
        for line in f:
            yield line.strip()

07Shallow copy vs deep copy?

A shallow copy copies the outer object but shares nested objects. copy.deepcopy copies everything.

08What is a decorator?

A function that wraps another function to add behaviour, like logging or retries, without changing its code.

09How do you handle errors?

With try, except, else and finally. Catch specific exceptions, not a bare except.

10What does with do?

It uses a context manager that sets up and cleans up a resource, like closing a file even if an error happens.

11What is the GIL?

The Global Interpreter Lock lets only one thread run Python bytecode at a time. For CPU work use multiprocessing; threads still help for I/O.

12Mutable default argument problem?

Defaults are created once, so def f(x=[]) shares the same list between calls. Use None and create the list inside.

13What is a virtual environment?

An isolated folder with its own Python packages, so projects do not conflict. Create one with python -m venv .venv.

14pandas: loc vs iloc?

loc selects by labels, iloc selects by integer position.

15How do you handle missing values in pandas?

Find them with isna(), then dropna() or fillna() depending on the business rule.

16merge vs concat in pandas?

merge joins DataFrames on keys like SQL. concat stacks them vertically or side by side.

17How do you read a very large CSV?

Use chunksize to process it in parts, select only needed columns with usecols, and set dtypes.

for chunk in pd.read_csv('big.csv', chunksize=100_000, usecols=['id', 'amount']):
    process(chunk)

18How do you call a REST API in Python?

Use requests with a timeout, check the status and parse JSON. Handle pagination and retries.

r = requests.get(url, timeout=30)
r.raise_for_status()
data = r.json()

19How do you test Python code?

With pytest: small test functions with assert, fixtures for setup, and tests run in CI on every change.

20What makes Python code production ready?

Clear functions, type hints, logging instead of print, config from environment variables, tests, and error handling with retries.

Keep going

Ready for the real interview?

Practise with our AI interviewer: 8 questions for your role, a score for every answer and a stronger answer to learn from.