Backend · Fresher-relevant
Python interview questions on data types, OOPs, decorators, generators, and libraries — widely tested for both backend and data science roles.
What is the difference between a list and a tuple in Python?
Tip: Lists are mutable and use more memory; tuples are immutable, hashable (so usable as dict keys), and slightly faster. Use tuples for fixed records and as dictionary keys; use lists for collections you will modify.
Explain the Global Interpreter Lock (GIL) and its impact on multithreading.
Tip: The GIL allows only one thread to execute Python bytecode at a time in CPython, so threads do not give true parallelism for CPU-bound work. Use multiprocessing (separate interpreters) for CPU-bound tasks and threading/asyncio for I/O-bound tasks where the GIL is released during blocking calls.
What are decorators in Python and how do they work?
Tip: A decorator is a callable that takes a function and returns a new function, used to wrap behaviour (logging, caching, auth) without modifying the original. @decorator is syntactic sugar for func = decorator(func). Use functools.wraps to preserve the wrapped function's metadata.
What is the difference between deep copy and shallow copy?
Tip: copy.copy() (shallow) duplicates the outer object but shares references to nested objects, so mutating a nested element affects both. copy.deepcopy() recursively copies everything, producing fully independent objects. Shallow copy is faster but risky with nested mutable data.
How does Python manage memory and what is reference counting?
Tip: CPython tracks each object's reference count and frees it when the count hits zero. A separate generational garbage collector breaks reference cycles (e.g. two objects referencing each other). The gc module exposes tuning and manual collection.
What is the difference between generators and lists? When would you use a generator?
Tip: A generator yields items lazily one at a time, holding only the current state in memory; a list materialises everything. Use generators for large or streaming datasets to keep memory flat. They are single-pass — once exhausted you must recreate them.
Explain *args and **kwargs.
Tip: *args collects extra positional arguments into a tuple; **kwargs collects extra keyword arguments into a dict. They let functions accept a variable number of arguments and are commonly used to forward arguments to wrapped functions in decorators.
What is the difference between is and == in Python?
Tip: == compares values (calls __eq__); is compares identity (same object in memory). Use is only for singletons like None (if x is None). Small integers (-5..256) and interned strings are cached, which can make is appear to work — never rely on that for value comparison.
InterviewEra generates role-specific questions using your actual projects and skills. Get scored feedback on technical depth, clarity, and structure — free to start.