Interview questions
Frequently asked questions with concise model answers. Try answering aloud before expanding.
What is the difference between a list and a tuple? Easy
Lists are mutable (can change) and use []; tuples are immutable and use (). Tuples are hashable (if their items are) so they can be dict keys, and are slightly faster and lighter.
Explain `*args` and `**kwargs`. Easy
*args collects extra positional arguments into a tuple; **kwargs collects extra keyword arguments into a dict. They make functions flexible and are common in decorators and wrappers.
What are decorators? Medium
A decorator is a function that takes a function and returns a new function, adding behaviour without modifying the original — e.g. logging, caching (functools.lru_cache), auth checks (@login_required).
What is the GIL? Hard
CPython's Global Interpreter Lock allows only one thread to execute Python bytecode at a time. CPU-bound work should use multiprocessing (or native extensions); I/O-bound work benefits from threads or asyncio.
Shallow vs deep copy? Medium
A shallow copy (copy.copy, list[:]) copies the outer container but shares nested objects. A deep copy (copy.deepcopy) recursively copies everything.