Recall & Review
beginner
What is the basic syntax to define a function in Python?
Use the
def keyword, followed by the function name, parentheses (), and a colon :. Then indent the function body below. Example:def my_function():
print("Hello")Click to reveal answer
beginner
What does the
return statement do inside a function?It sends a value back to where the function was called. This lets the function give back a result. Without
return, the function returns None by default.Click to reveal answer
beginner
Can a Python function have parameters? How are they used?
Yes, parameters are names inside the parentheses in the function definition. They act like placeholders for values you give when calling the function. Example:
def greet(name):
print(f"Hello, {name}!")Click to reveal answer
intermediate
What happens if you call a function without parentheses?
You get a reference to the function itself, not the result of running it. To run the function and get its output, you must use parentheses, even if empty.
Click to reveal answer
beginner
Why is indentation important in Python function definitions?
Indentation shows which lines belong inside the function. Python uses indentation instead of braces. Without correct indentation, Python will give an error or run code incorrectly.
Click to reveal answer
Which keyword is used to define a function in Python?
✗ Incorrect
The correct keyword to define a function in Python is
def.What will this function return if called without a return statement?
def add(a, b):
c = a + b✗ Incorrect
Without a
return statement, Python functions return None by default.How do you call a function named
say_hello with no parameters?✗ Incorrect
You call a function by writing its name followed by parentheses, even if empty.
What is the purpose of parameters in a function?
✗ Incorrect
Parameters are placeholders for values you pass into the function when calling it.
Why must the function body be indented in Python?
✗ Incorrect
Python uses indentation to know which lines belong inside the function or other blocks.
Explain how to define a simple function in Python that takes one parameter and returns a value.
Think about the parts you need to write a function that gives back a result.
You got /6 concepts.
Describe why indentation is important in Python function definitions and what happens if it is missing.
Consider how Python knows which lines belong inside the function.
You got /4 concepts.