0
0
Pythonprogramming~5 mins

Return values in Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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
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
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
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
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
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.