Skip to content
QuiznExam

Functions & Lambda in Python

Test your knowledge of functions and lambda expressions in Python, including defining functions, parameters, arguments, return values, default arguments, keyword arguments, *args, **kwargs, scope, and lambda functions.

15
Questions
12 min
Time limit
Medium
Difficulty

No sign-up needed · Last updated:

Save your score

At least 8 characters.

Forgot password?

Related quizzes

All 15 questions and answers Spoilers: this shows the questions and answers. Try the quiz first! Open
  1. 1. Which keyword is used to define a function in Python?

    • A. def
    • B. function
    • C. func
    • D. define
    Show answer

    A. def

    The def keyword is used to define a function in Python.

  2. 2. Which statement is used to return a value from a Python function?

    • A. return
    • B. send
    • C. output
    • D. yield_value
    Show answer

    A. return

    The return statement exits the function and can provide a value to the caller.

  3. 3. What is the correct way to define a function that accepts one parameter?

    • A. def greet(name):
    • B. function greet(name):
    • C. def greet = (name):
    • D. create greet(name):
    Show answer

    A. def greet(name):

    Python functions are defined using def followed by the function name and its parameters in parentheses.

  4. 4. What is an argument in Python?

    • A. A value passed to a function when it is called
    • B. The name of a function
    • C. A value returned only by a function
    • D. A Python module
    Show answer

    A. A value passed to a function when it is called

    An argument is a value supplied to a function when the function is called.

  5. 5. What is a default parameter value used for?

    • A. To provide a value when an argument is not supplied
    • B. To prevent a function from being called
    • C. To make every parameter required
    • D. To automatically delete the parameter
    Show answer

    A. To provide a value when an argument is not supplied

    A default parameter provides a predefined value that is used when the caller does not provide an argument for that parameter.

  6. 6. What does *args allow a Python function to accept?

    • A. A variable number of positional arguments
    • B. Only one keyword argument
    • C. Only string arguments
    • D. A variable number of modules
    Show answer

    A. A variable number of positional arguments

    The *args syntax collects additional positional arguments into a tuple.

  7. 7. What does **kwargs allow a Python function to accept?

    • A. A variable number of keyword arguments
    • B. Only positional arguments
    • C. Only integer arguments
    • D. A variable number of functions
    Show answer

    A. A variable number of keyword arguments

    The **kwargs syntax collects additional keyword arguments into a dictionary.

  8. 8. What type of object does a lambda expression create in Python?

    • A. A function
    • B. A class
    • C. A module
    • D. A list
    Show answer

    A. A function

    A lambda expression creates a function object, typically used for short anonymous functions.

  9. 9. Which syntax correctly defines a lambda function that adds two numbers?

    • A. lambda x, y: x + y
    • B. lambda(x, y) => x + y
    • C. lambda x, y -> x + y
    • D. function lambda(x, y): x + y
    Show answer

    A. lambda x, y: x + y

    Python lambda expressions use the lambda keyword, followed by parameters, a colon, and a single expression.

  10. 10. Which statement about Python lambda functions is correct?

    • A. A lambda body contains a single expression
    • B. A lambda must contain multiple statements
    • C. A lambda cannot accept parameters
    • D. A lambda can only return strings
    Show answer

    A. A lambda body contains a single expression

    A lambda function consists of a parameter list and a single expression whose result is returned.

  11. 11. What will the following function return when called as add(3, 4)? def add(a, b): return a + b

    • A. 7
    • B. 34
    • C. 12
    • D. None
    Show answer

    A. 7

    The function adds the two numeric arguments, so 3 + 4 returns 7.

  12. 12. Which scope is normally used for a variable created inside a Python function?

    • A. Local scope
    • B. Global scope
    • C. Module-only scope
    • D. System scope
    Show answer

    A. Local scope

    A variable assigned inside a function is normally local to that function unless declared otherwise.

  13. 13. Which built-in function can be used to call a function with an iterable's elements as positional arguments?

    • A. The function can be called using the * unpacking operator
    • B. The function must always use **
    • C. The function must use unpack()
    • D. The function must use spread()
    Show answer

    A. The function can be called using the * unpacking operator

    The * operator can unpack an iterable into positional arguments when calling a function, such as func(*values).

  14. 14. What is the main purpose of using keyword arguments when calling a Python function?

    • A. To specify arguments by parameter name
    • B. To convert arguments into strings
    • C. To prevent the function from returning a value
    • D. To make all arguments global
    Show answer

    A. To specify arguments by parameter name

    Keyword arguments allow callers to associate values explicitly with parameter names, such as greet(name="Alex").

  15. 15. Which built-in function is commonly used with a lambda to transform each item in an iterable?

    • A. map()
    • B. change()
    • C. transform()
    • D. iterate()
    Show answer

    A. map()

    The map() function applies a function, often a lambda, to each item of an iterable and returns a map iterator.