QuizzesFunctions — def, Return Values & Default Arguments — Concept Check
intermediate
python

Functions — def, Return Values & Default Arguments — Concept Check

Questions on Functions — def, Return Values & Default Arguments. Functions are first-class objects defined with def, returning None unless told otherwise — with keyword arguments and default values that make call sites self-documenting.

8 minutes 8 questions Pass at 70%
Time Limit
8 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

8 questions on Functions — def, Return Values & Default Arguments — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.You have a function defined as `def add_item(item, items=[])`. After calling `add_item('apple')` and `add_item('banana')`, what does `add_item('cherry')` return?

    • A['apple', 'cherry']
    • B['cherry']
    • C['banana', 'cherry']
    • D['apple', 'banana', 'cherry']
  2. 2.A function is defined as `def calculate(a, b=5)`. What happens when you call `calculate(3)`?

    • AIt uses the default value for `b`.
    • BIt returns None because no return statement is present.
    • CIt raises an error due to missing argument.
    • DIt returns a tuple with default values.
  3. 3.Given the function `def func(x, y=10): return x + y`, what does `func(y=5, x=3)` return?

    • A15
    • B8
    • C13
    • DError due to wrong argument order
  4. 4.What is the result of `apply_discount(price=1000, percent=0)`?

    • A900.0
    • BNone
    • C0.0
    • D1000.0
  5. 5.If `min_max([3, 7, 2])` is called, what does it return?

    • A(3, 7)
    • B(2, 3, 7)
    • C(2, 7)
    • D[2, 7]
  6. 6.Why is it a bad practice to use a mutable default argument like a list in a function definition?

    • AIt causes syntax errors.
    • BIt makes the function slower.
    • CIt leads to unexpected behavior across calls.
    • DIt increases memory usage.
  7. 7.A developer uses `def add_task(task, tasks=None): if tasks is None: tasks = []`. Why is this pattern preferred?

    • AIt prevents the function from returning None.
    • BIt avoids syntax errors.
    • CIt ensures a new list is created for each call.
    • DIt is faster than using a list directly.
  8. 8.What happens if a function does not have a return statement?

    • AIt returns None.
    • BIt returns 0.
    • CIt returns an empty string.
    • DIt causes a runtime error.