Python Programming - Functions

Exercise : Functions - General Questions
  • Functions - General Questions
1.
What is the purpose of the def keyword?
Defines a variable
Declares a function
Imports a module
Checks the equality of two values
Answer: Option
Explanation:
The def keyword is used to define a function in Python.

2.
What will be the result of the following code snippet?
def add_numbers(a, b):
    return a + b

result = add_numbers(3, 7)
print(result)
10
21
'37'
Error
Answer: Option
Explanation:
The function add_numbers adds the values of a and b (3 + 7), resulting in 10.

3.
How do you pass a default value to a function parameter?
function(parameter:=default_value)
function(default_value=parameter)
function(parameter, default_value)
function(parameter=default_value)
Answer: Option
Explanation:
Default values for function parameters are assigned using the parameter=default_value syntax.

4.
What is the purpose of the return statement in a function?
Prints a value to the console
Terminates the program
Exits the function and returns a value
Declares a variable
Answer: Option
Explanation:
The return statement is used to exit a function and return a value to the caller.

5.
What does the term "function signature" refer to?
The name of the function
The entire function body
The list of parameters and their types
The return statement of the function
Answer: Option
Explanation:
The function signature includes the name of the function and the list of parameters along with their types.