Interview Q&A / Python
Python interview questions
Lists, dictionaries, generators, decorators and the Python questions asked in service-company and data roles.
Prefer rapid revision? Practise Python short interview answers →
- What are *args and **kwargs in Python?
In a function definition, *args collects any extra positional arguments into a tuple, and **kwargs collects any extra keyword arguments into a dict. They let a function accept a variable number of inputs. The same * and ** symbols also unpack a list or dict when calling a function.
BeginnerIn-depth3 min read - What do the / and * markers in a Python function signature mean?
Parameters before / are positional-only, so callers cannot pass them by name. Parameters after a bare * are keyword-only, so callers must pass them by name. Both make an API clearer and safer to change.
IntermediateQuick answer1 min read