Python · Module 4Module material
Functions interview questions
25 questions interviewers ask on this module’s topics, from first principles to the follow-ups. Each comes with a model answer.
Defining and calling
- What is the difference between a parameter and an argument?●
- What does a function return if it has no
returnstatement?● - How do you return several values from a function?●
- What is the difference between
with_taxandwith_tax(12.50)?●● - Are type hints enforced?●●
- What is a docstring, and how do you read one?●
Arguments
- What is the difference between positional and keyword arguments?●
- What are
*argsand**kwargs?●● - What does a bare
*or a/mean in a signature?●● - What is the mutable default argument problem?●●
- Does Python pass arguments by value or by reference?●●
Scope
- What is the LEGB rule?●
- Why does
count += 1inside a function raiseUnboundLocalErrorwhencountis a global?●● - What happens to a function's local variables when it returns?●●
Recursion
- What are the two parts of a recursive function?●
- What is a
RecursionError, and what causes it?●● - When would you choose recursion over a loop?●●
- What is the call stack?●●
Functions as values
- What is a lambda, and what can it not contain?●
- How does
key=work insorted,minandmax?●● - What does it mean that Python's sort is stable, and why does it matter?●●
- What do
mapandfilterreturn? Would you use them?●● - What is a higher-order function? Give an example.●●
- What does this print, and why?
fs = [lambda: i for i in range(3)], then[f() for f in fs].●● - What does
functools.cachedo?●●