This answer key contains 4 multiple-choice, 4 fill-in-the-blank, and 4 output-prediction questions for Python Functions, with the exact answer and a short explanation for every question.
The answers are shown in full, so use this page after making an attempt. The practice page is the better first pass.
Which keyword defines a function in Python?
Answer: def
Why: A function definition starts with def, followed by its name and parameters.
What does return do inside a function?
Answer: Sends a value back to the caller
Why: return ends the function and gives its result to the caller.
Which definition gives name a default value?
Answer: def greet(name="friend"):
Why: A default value follows an equals sign in the parameter list.
What does a function with no return statement return?
Answer: None
Why: If a function reaches the end without return, Python returns None.
Complete the keyword that starts the function definition.
____ add(a, b):
return a + bAnswer: def
Why: def introduces a function definition.
Complete the expression so add returns a plus b.
def add(a, b):
return a ____ bAnswer: +
Why: The addition operator combines the two parameters.
Complete the default value so greet() says Hi friend.
def greet(name="____"):
return f"Hi {name}"Answer: friend
Why: The default is used when the caller does not supply a name.
Complete the expression so the function result is printed.
result = add(2, 3)
print(____)Answer: result
Why: The variable result holds the value returned by add.
What is the output?
def add(a, b):
return a + b
print(add(2, 3))Answer: 5
Why: The function returns 5, then print displays it.
What does this code print?
def greet(name="Maya"):
return f"Hi {name}"
print(greet())Answer: Hi Maya
Why: The default name Maya is used when no argument is passed.
What does the program output?
def square(n):
return n * n
print(square(4))Answer: 16
Why: 4 squared is 16.
What appears on the screen?
def no_return():
pass
print(no_return())Answer: None
Why: A function without a return value produces None.
Try the questions first
Open the practice page for Python Functions and answer the same 12 questions with instant feedback.