Robotics & Artificial Intelligence
What is the purpose of return statement in Python functions?
- It is used to terminate the execution of a function
- It is used to define the output of a function
- It is used to import modules into a function
- None of these
Answer
It is used to terminate the execution of a function
Reason — The return statement ends the execution of a function and transfers the control back to the place where the function was called. Once the return statement is executed, no further statements in the function body are executed.
Related Questions
The structure of function header in Python is:
- "def" keyword followed by the function name and parameters
- "func" keyword followed by the function name and parameters
- "def" keyword followed by the return type, function name and parameters
- "define" keyword followed by the function name and parameters
A function in Python is called by:
- using the "call" keyword followed by the function name and parameters
- using the "invoke" keyword followed by the function name and parameters
- using the function name followed by parenthesis and arguments
- using the "run" keyword followed by the function name and parameters
What would be output of the following code snippet?
def multiply(x, y=2): return x * y result = multiply(5) print(result)- 5
- 10
- 2
- Error
In the following code snippet, what does 5 in the argument list represent?
def add(x, y=5): return x + y- return value
- default value
- input value
- None of these