Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What does it mean when a Python function returns multiple values?
It means the function sends back more than one piece of information at once, usually as a tuple, so you can use them separately.
Click to reveal answer
beginner
How do you capture multiple return values from a function in Python?
You can assign the returned values to multiple variables separated by commas, like: a, b = my_function()
Click to reveal answer
beginner
What type does Python use to hold multiple return values by default?
Python uses a tuple to hold multiple return values by default.
Click to reveal answer
beginner
Can a Python function return different types of values together? For example, a number and a string?
Yes, Python functions can return different types together, like a number and a string, because tuples can hold mixed types.
Click to reveal answer
intermediate
What happens if you try to assign multiple return values to fewer variables than returned?
Python will raise a ValueError because the number of variables does not match the number of returned values.
Click to reveal answer
What does a Python function return when you write: return 1, 2, 3?
AAn error because multiple values are not allowed
BA list containing [1, 2, 3]
CThree separate values returned one by one
DA tuple containing (1, 2, 3)
✗ Incorrect
Python automatically packs multiple return values into a tuple.
How do you receive multiple return values from a function?
AAssign them to multiple variables separated by commas
BUse a single variable only
CUse a list to capture them
DYou cannot receive multiple return values
✗ Incorrect
You assign multiple variables separated by commas to capture each returned value.
What error occurs if you assign two variables to a function returning three values?
AValueError
BTypeError
CSyntaxError
DNo error
✗ Incorrect
Python raises a ValueError when the number of variables does not match the number of returned values.
Can a function return a string and an integer together?
AOnly if converted to integer
BYes, as a tuple
COnly if converted to string
DNo, only same types allowed
✗ Incorrect
Python tuples can hold mixed data types, so a string and integer can be returned together.
What is the default container type for multiple return values in Python?
ADictionary
BList
CTuple
DSet
✗ Incorrect
Python packs multiple return values into a tuple by default.
Explain how Python functions can return multiple values and how you can use them.
Think about how you get more than one answer from a function.
You got /3 concepts.
Describe what happens if the number of variables on the left does not match the number of returned values from a function.
Consider what Python expects when unpacking values.
You got /3 concepts.
Practice
(1/5)
1.
What does a Python function return when it has multiple values separated by commas in the return statement?
easy
A. A tuple containing all the returned values
B. A list containing all the returned values
C. Only the first value is returned
D. A dictionary with values as keys
Solution
Step 1: Understand Python return behavior
When multiple values are separated by commas in a return statement, Python groups them into a tuple automatically.
Step 2: Identify the returned data type
The returned object is a tuple containing all the values, not a list or dictionary.
Final Answer:
A tuple containing all the returned values -> Option A
Quick Check:
Multiple values returned = tuple [OK]
Hint: Multiple returns become a tuple automatically [OK]
Common Mistakes:
Thinking it returns a list
Assuming only one value is returned
Confusing tuple with dictionary
2.
Which of the following is the correct syntax to return multiple values a and b from a function?
easy
A. return a, b
B. return {a: b}
C. return [a, b]
D. return {a, b}
Solution
Step 1: Review return syntax for multiple values
Python allows returning multiple values separated by commas without parentheses.
Step 2: Compare options
return a, b is correct and returns a tuple. return {a: b} returns a dictionary, return [a, b] returns a list, and return {a, b} returns a set, which are not typical for multiple return values.
Final Answer:
return a, b -> Option A
Quick Check:
Comma-separated values return tuple [OK]
Hint: Use commas without brackets to return multiple values [OK]