Recall & Review
beginner
What are keyword arguments in Python functions?
Keyword arguments are arguments passed to a function by explicitly naming each parameter and assigning it a value. This allows you to specify which argument corresponds to which parameter, regardless of their order.
Click to reveal answer
beginner
How do keyword arguments improve function calls?
They make function calls clearer and easier to read by naming each argument. They also allow skipping some optional parameters and changing the order of arguments without confusion.
Click to reveal answer
beginner
Example: What does this function call do?
def greet(name, age):
print(f"Hello {name}, you are {age} years old.")
greet(age=30, name='Alice')This calls the greet function using keyword arguments. It prints: "Hello Alice, you are 30 years old." The order of arguments is switched but still works because keywords are used.
Click to reveal answer
intermediate
Can you mix positional and keyword arguments in a function call?
Yes, but positional arguments must come first, followed by keyword arguments. For example:
func(1, 2, c=3) is valid, but func(a=1, 2) is not.Click to reveal answer
intermediate
What happens if you pass the same argument both positionally and as a keyword?
Python raises a TypeError because the function receives multiple values for the same parameter, which causes confusion.
Click to reveal answer
What is the main benefit of using keyword arguments in Python?
✗ Incorrect
Keyword arguments let you specify arguments in any order by naming them explicitly.
Which of the following is a valid function call using keyword arguments?
✗ Incorrect
func(a=1, b=2) uses only keyword arguments and is valid. Option D is invalid because positional arguments cannot follow keyword arguments.
What error occurs if you pass the same argument twice, once positionally and once as a keyword?
✗ Incorrect
Python raises a TypeError when a parameter receives multiple values.
Can you omit some arguments when using keyword arguments if the function has default values?
✗ Incorrect
Keyword arguments allow skipping parameters that have default values.
Which of these is NOT true about keyword arguments?
✗ Incorrect
Keyword arguments must come after positional arguments, not before.
Explain what keyword arguments are and why they are useful in Python functions.
Think about how naming arguments helps when calling functions.
You got /4 concepts.
Describe the rules for mixing positional and keyword arguments in a function call.
Consider the order and uniqueness of arguments.
You got /4 concepts.