Question:
unpack(*, **), args, kwargs
How often asked: Often
Suggested by: ALittleMoron
Answer:
Unpacking is used in various contexts when using sequences. Sometimes they can be used to recreate data structures. Sometimes, it's possible to pass an indefinite number of arguments to functions or class instances.
args is a conventionally accepted keyword used in functions as a parameter to which an indefinite number of non-positional arguments are passed. A non-positional argument is one passed without the = sign. It can be replaced with a positional sequence parameter.
kwargs is a similarly conventionally accepted keyword used in functions as a parameter to which an indefinite number of positional arguments are passed. Positional arguments are those passed using =.
args and kwargs are not reserved words and can be named anything. The main thing is that non-positional arguments use a single asterisk *, and positional arguments use two asterisks **. An example of such a function:
def foo (a, *b, **c):
...
Interview answer explanation:
The question is actually tricky. The syntax * and ** can be used for both unpacking and passing non-positional and positional arguments, respectively.
The main challenge for new developers is understanding the difference. Knowing these differences helps ensure that the candidate understands the fundamentals and has a general understanding of Python functions.