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 the return statement do in a Python function?
It sends a value back to the place where the function was called, allowing the program to use that value later.
Click to reveal answer
beginner
Can a Python function return more than one value?
Yes, by returning multiple values separated by commas, Python actually returns a tuple containing those values.
Click to reveal answer
beginner
What happens if a Python function does not have a return statement?
The function returns None by default, which means it does not send any useful value back.
Click to reveal answer
beginner
How do you capture the value returned by a function?
You assign the function call to a variable, like result = my_function(), so you can use the returned value later.
Click to reveal answer
intermediate
Is it possible to have multiple return statements in one function?
Yes, you can have several return statements inside different parts of a function to return different values based on conditions.
Click to reveal answer
What does a Python function return if it has no return statement?
AAn empty string
B0
CNone
DAn error
✗ Incorrect
If no return is used, Python functions return None by default.
How can a function return multiple values in Python?
ABy returning a tuple of values separated by commas
BBy using multiple <code>return</code> statements at once
CBy printing values instead of returning
DBy calling another function inside
✗ Incorrect
Returning multiple values separated by commas actually returns a tuple containing those values.
What is the correct way to get the value returned by a function?
AUse <code>input()</code> after the function
BCall the function without assignment
CPrint the function name
DAssign the function call to a variable
✗ Incorrect
Assigning the function call to a variable stores the returned value for later use.
Can a function have more than one return statement?
ANo, only one <code>return</code> is allowed
BYes, to return different values based on conditions
CYes, but only if they return the same value
DNo, it causes a syntax error
✗ Incorrect
Multiple return statements can be used to return different values depending on conditions.
What type of value does a function return if it uses return 5, 10?
AA tuple containing (5, 10)
BA list containing [5, 10]
CAn error because of multiple values
DOnly the first value 5
✗ Incorrect
Returning multiple values separated by commas returns a tuple with those values.
Explain in your own words what a return value is and why it is useful in a function.
Think about how a function can give you information after it finishes.
You got /3 concepts.
Describe how you can return multiple values from a Python function and how to use them after calling the function.
Remember that multiple values come back as a single package you can unpack.
You got /3 concepts.
Practice
(1/5)
1. What does the return statement do in a Python function?
easy
A. It sends a value back to where the function was called.
B. It prints a value to the screen.
C. It creates a new variable inside the function.
D. It pauses the function without sending any value.
Solution
Step 1: Understand the purpose of return
The return statement ends the function and sends a value back to the caller.
Step 2: Differentiate from printing or pausing
Printing shows output but does not send a value back; pausing does not return a value.
Final Answer:
It sends a value back to where the function was called. -> Option A
Quick Check:
Return sends value back [OK]
Hint: Return sends value back, print shows output only [OK]
Common Mistakes:
Confusing return with print
Thinking return pauses without value
Assuming return creates variables
2. Which of the following is the correct syntax to return the value 10 from a function?
easy
A. return(10,)
B. return 10
C. return = 10
D. return: 10
Solution
Step 1: Recall correct return syntax
The correct syntax is simply return followed by the value without assignment or colon.
Step 2: Check each option
return 10 is correct; return(10,) returns a tuple (10,) due to the trailing comma; the others cause syntax errors.
Final Answer:
return 10 -> Option B
Quick Check:
Return value with 'return value' syntax [OK]
Hint: Use 'return value' without assignment or colon [OK]
Common Mistakes:
Using assignment with return
Adding colon after return
Using parentheses incorrectly
3. What is the output of this code?
def add(a, b):
return a + b
result = add(3, 4)
print(result)
medium
A. None
B. 34
C. 7
D. Error
Solution
Step 1: Understand the function behavior
The function add returns the sum of a and b.
Step 2: Calculate the return value
Calling add(3, 4) returns 7, which is stored in result and printed.
Final Answer:
7 -> Option C
Quick Check:
3 + 4 = 7 [OK]
Hint: Return value is sum, printed as 7 [OK]
Common Mistakes:
Concatenating numbers as strings
Forgetting to return value
Expecting print inside function
4. Find the error in this function and choose the correct fix:
def multiply(x, y):
product = x * y
print(product)
medium
A. Add return x, y instead of product.
B. Change print(product) to return print(product).
C. Remove product and just print x * y.
D. Add return product to send the result back.
Solution
Step 1: Identify the problem
The function prints the product but does not return it, so no value is sent back.
Step 2: Fix by returning the product
Adding return product sends the result back to the caller.
Final Answer:
Add return product to send the result back. -> Option D
Quick Check:
Return value to send result back [OK]
Hint: Return value to send it back, print only shows output [OK]
Common Mistakes:
Returning print() instead of value
Not returning any value
Returning wrong variables
5. You want a function that returns the first non-empty string from a list or None if all are empty. Which function correctly does this?
hard
A. def first_non_empty(strings):
for s in strings:
if s:
return s
return None
B. def first_non_empty(strings):
for s in strings:
if s == '':
return s
return None
C. def first_non_empty(strings):
for s in strings:
if not s:
return s
return None
D. def first_non_empty(strings):
for s in strings:
return s
return None
Solution
Step 1: Understand the goal
The function should return the first string that is not empty (truthy) or None if none found.
Step 2: Analyze each option
The version with if not s: return s returns the first falsy (empty) string; if s == '' returns the first exactly empty string; if s: return s returns the first truthy (non-empty) string; the version without if returns the first string regardless. Only the truthy check is correct.
Final Answer:
def first_non_empty(strings):
for s in strings:
if s:
return s
return None -> Option A