33 lessons
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

  1. What is the difference between a parameter and an argument?●
  2. What does a function return if it has no return statement?●
  3. How do you return several values from a function?●
  4. What is the difference between with_tax and with_tax(12.50)?●●
  5. Are type hints enforced?●●
  6. What is a docstring, and how do you read one?●

Arguments

  1. What is the difference between positional and keyword arguments?●
  2. What are *args and **kwargs?●●
  3. What does a bare * or a / mean in a signature?●●
  4. What is the mutable default argument problem?●●
  5. Does Python pass arguments by value or by reference?●●

Scope

  1. What is the LEGB rule?●
  2. Why does count += 1 inside a function raise UnboundLocalError when count is a global?●●
  3. What happens to a function's local variables when it returns?●●

Recursion

  1. What are the two parts of a recursive function?●
  2. What is a RecursionError, and what causes it?●●
  3. When would you choose recursion over a loop?●●
  4. What is the call stack?●●

Functions as values

  1. What is a lambda, and what can it not contain?●
  2. How does key= work in sorted, min and max?●●
  3. What does it mean that Python's sort is stable, and why does it matter?●●
  4. What do map and filter return? Would you use them?●●
  5. What is a higher-order function? Give an example.●●
  6. What does this print, and why? fs = [lambda: i for i in range(3)], then [f() for f in fs].●●
  7. What does functools.cache do?●●

Directory listings

  • SchoolWhool on Siteefy