0
0
Pythonprogramming~5 mins

Parameters and arguments in Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AParameters
BArguments
CFunctions
DVariables outside the function
What is the argument in the call add(3, 5)?
Ax and y
Badd
C3 and 5
DFunction name
What error occurs if you call greet(name) without an argument?
ASyntaxError
BValueError
CNameError
DTypeError
Which of these is a correct way to define a default parameter?
Adef greet('Friend' = name):
Bdef greet(name='Friend'):
Cdef greet(name): name='Friend'
Ddef greet(name): return 'Friend'
If a function has parameters a, b=2, what happens when you call it with func(5)?
Aa=5 and b=2 (default used)
Ba=2 and b=5
CError because b is missing
DBoth a and b are 5
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.