01List vs tuple?
Lists are mutable, tuples are immutable. Tuples can be dictionary keys and are slightly faster.
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.
Lists are mutable, tuples are immutable. Tuples can be dictionary keys and are slightly faster.
A key to value mapping built on a hash table, so lookups are O(1) on average. Keys must be hashable.
== compares values. is checks if two names point to the same object. Use is only for None.
*args collects extra positional arguments into a tuple, **kwargs collects extra keyword arguments into a dict.
A short way to build a list from a loop and an optional condition.
squares = [x * x for x in nums if x > 0]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()A shallow copy copies the outer object but shares nested objects. copy.deepcopy copies everything.
A function that wraps another function to add behaviour, like logging or retries, without changing its code.
With try, except, else and finally. Catch specific exceptions, not a bare except.
It uses a context manager that sets up and cleans up a resource, like closing a file even if an error happens.
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.
Defaults are created once, so def f(x=[]) shares the same list between calls. Use None and create the list inside.
An isolated folder with its own Python packages, so projects do not conflict. Create one with python -m venv .venv.
loc selects by labels, iloc selects by integer position.
Find them with isna(), then dropna() or fillna() depending on the business rule.
merge joins DataFrames on keys like SQL. concat stacks them vertically or side by side.
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)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()With pytest: small test functions with assert, fixtures for setup, and tests run in CI on every change.
Clear functions, type hints, logging instead of print, config from environment variables, tests, and error handling with retries.
Practise with our AI interviewer: 8 questions for your role, a score for every answer and a stronger answer to learn from.