Interview Prep | Python
Python Interview Questions

Entry, Mid, and Advanced Python questions with short answers. Use search to filter questions quickly.

🔍

Python Entry Level Q&A

Back to Top ↑
🐍
Q1. List vs tuple?
A. Lists are mutable; tuples are immutable and can be used as dict keys if items are hashable.
Entry
🐍
Q2. What are *args and **kwargs?
A. *args collects extra positional args; **kwargs collects extra keyword args.
Entry
🐍
Q3. What is a dict and how is it used?
A. A key-value mapping. Access values by key; keys must be hashable.
Entry
🐍
Q4. is vs ==?
A. == compares values; is compares identity (same object).
Entry
🐍
Q5. What is a generator?
A. A lazy iterator created with yield. It produces values on demand and saves memory.
Entry
🐍
Q6. What is a list comprehension?
A. A concise way to build lists: [expr for x in iterable if cond].
Entry
🐍
Q7. What is exception handling?
A. Use try/except to handle errors; finally for cleanup; raise to throw exceptions.
Entry
🐍
Q8. What is PEP 8?
A. Python style guide covering formatting and conventions for readable code.
Entry

Python Mid Level Q&A

Back to Top ↑
⚙️
Q1. What is a context manager?
A. Used with with-statement to manage setup/teardown (files, locks). Implemented via __enter__/__exit__.
Mid
⚙️
Q2. Shallow vs deep copy?
A. Shallow copy shares nested objects; deep copy recursively copies nested objects.
Mid
⚙️
Q3. @staticmethod vs @classmethod?
A. @staticmethod has no self/cls. @classmethod receives cls and is used for alternative constructors.
Mid
⚙️
Q4. What is a dataclass?
A. A helper that generates boilerplate (__init__, __repr__, etc.) for data-holding classes.
Mid
⚙️
Q5. What is the iterator protocol?
A. Objects implement __iter__ and __next__ to be iterable; StopIteration ends iteration.
Mid
⚙️
Q6. Threads vs processes?
A. Threads share memory; processes have separate memory and can use multiple CPU cores.
Mid
⚙️
Q7. What is a virtual environment?
A. An isolated environment for dependencies (venv) to avoid global package conflicts.
Mid
⚙️
Q8. How do you type hint in Python?
A. Use annotations (PEP 484) like def f(x: int) -> str: ... and tools like mypy.
Mid

Python Advanced Level Q&A

Back to Top ↑
🚀
Q1. What is the GIL?
A. In CPython, the Global Interpreter Lock allows only one thread to execute Python bytecode at a time (affects CPU-bound threading).
Advanced
🚀
Q2. When to use multiprocessing vs asyncio?
A. multiprocessing for CPU-bound parallelism; asyncio for high-concurrency I/O-bound tasks.
Advanced
🚀
Q3. What are descriptors?
A. Objects implementing __get__/__set__/__delete__ that customize attribute access (property uses descriptors).
Advanced
🚀
Q4. What is MRO?
A. Method Resolution Order defines how Python resolves methods in multiple inheritance (C3 linearization).
Advanced
🚀
Q5. Monkey patching risks?
A. Runtime modification can break assumptions, complicate debugging, and cause subtle side effects across modules.
Advanced
🚀
Q6. What is a decorator used for?
A. A function that wraps another to add behavior (logging, caching, auth) without changing its code.
Advanced
🚀
Q7. How do you prevent SQL injection?
A. Use parameterized queries / ORM binding; never string-concatenate untrusted input into SQL.
Advanced
🚀
Q8. What is safe serialization?
A. Prefer JSON for interoperability; avoid untrusted pickle (can execute code).
Advanced