Recall & Review
beginner
What is a parameter in a Python function?
A parameter is a named variable in a function definition that acts as a placeholder for the value that will be passed to the function when it is called.
Click to reveal answer
beginner
What is an argument in Python?
An argument is the actual value or data you provide to a function when you call it. It fills the parameter's placeholder.
Click to reveal answer
beginner
Explain the difference between parameters and arguments with an example.
In
def greet(name):, name is a parameter. When you call greet('Alice'), 'Alice' is the argument passed to the parameter name.Click to reveal answer
intermediate
What happens if you call a function without providing an argument for a parameter that has no default value?
Python will raise a
TypeError because the function expects an argument for that parameter but none was given.Click to reveal answer
intermediate
What are default parameters in Python functions?
Default parameters are parameters that have a default value assigned in the function definition. If no argument is provided for them, the default value is used.
Click to reveal answer
In the function definition
def add(x, y):, what are x and y?✗ Incorrect
x and y are parameters because they are placeholders in the function definition.What is the argument in the call
add(3, 5)?✗ Incorrect
The values
3 and 5 are arguments passed to the function.What error occurs if you call
greet(name) without an argument?✗ Incorrect
A
TypeError occurs because the required argument is missing.Which of these is a correct way to define a default parameter?
✗ Incorrect
Default parameters are set in the function definition like
name='Friend'.If a function has parameters
a, b=2, what happens when you call it with func(5)?✗ Incorrect
Parameter
b uses its default value 2 when no argument is given.Explain in your own words the difference between parameters and arguments in Python functions.
Think about how you prepare a recipe (parameters) and how you actually cook with ingredients (arguments).
You got /4 concepts.
Describe what happens if you call a function without providing all required arguments.
Imagine forgetting to bring an ingredient to cook a recipe.
You got /3 concepts.