Answer key · 12 questions

Python Functions Exercises With Answers

All 12 questions for Python Functions in one place. Try the practice page first, then use this page to check the exact answer and the reason.

Quick answer

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.

01 · Multiple choice

Which keyword defines a function in Python?

  1. function
  2. lambda
  3. func
  4. defcorrect

Answer: def

Why: A function definition starts with def, followed by its name and parameters.

02 · Multiple choice

What does return do inside a function?

  1. Sends a value back to the callercorrect
  2. Stops the whole program
  3. Prints a value
  4. Creates a new variable

Answer: Sends a value back to the caller

Why: return ends the function and gives its result to the caller.

03 · Multiple choice

Which definition gives name a default value?

  1. def greet("friend"=name):
  2. def greet(name) default "friend":
  3. def greet(name): = "friend"
  4. def greet(name="friend"):correct

Answer: def greet(name="friend"):

Why: A default value follows an equals sign in the parameter list.

04 · Multiple choice

What does a function with no return statement return?

  1. An empty string
  2. 0
  3. It raises an error
  4. Nonecorrect

Answer: None

Why: If a function reaches the end without return, Python returns None.

05 · Fill in the blank

Complete the keyword that starts the function definition.

____ add(a, b):
    return a + b

Answer: def

Why: def introduces a function definition.

06 · Fill in the blank

Complete the expression so add returns a plus b.

def add(a, b):
    return a ____ b

Answer: +

Why: The addition operator combines the two parameters.

07 · Fill in the blank

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.

08 · Fill in the blank

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.

09 · Predict output

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.

10 · Predict output

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.

11 · Predict output

What does the program output?

def square(n):
    return n * n
print(square(4))

Answer: 16

Why: 4 squared is 16.

12 · Predict output

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.

Practice this lesson