Recall & Review
beginner
What does
*args mean in a Python function?*args allows a function to accept any number of positional arguments as a tuple.
Click to reveal answer
beginner
How do you access the third argument passed using
*args?You access it like a tuple element: args[2] (index starts at 0).
Click to reveal answer
beginner
Can a function have both regular parameters and
*args?Yes, regular parameters come first, then *args to catch extra positional arguments.
Click to reveal answer
beginner
What type is
args inside the function when using *args?args is a tuple containing all extra positional arguments passed.
Click to reveal answer
beginner
Write a simple function using
*args that prints all arguments.def print_all(*args):
for arg in args:
print(arg)
Click to reveal answer
What does
*args collect inside a function?✗ Incorrect
*args collects extra positional arguments as a tuple.
How do you define a function that accepts any number of positional arguments?
✗ Incorrect
Use *args to accept variable positional arguments.
If a function is defined as
def f(a, *args):, what happens when you call f(1, 2, 3)?✗ Incorrect
The first argument goes to a, the rest go into args tuple.
What is the type of
args inside the function?✗ Incorrect
args is always a tuple.
Can
*args be used to accept keyword arguments?✗ Incorrect
*args is for positional arguments; **kwargs is for keyword arguments.
Explain how
*args works in a Python function and give an example.Think about how to catch extra inputs without naming them all.
You got /3 concepts.
Describe the difference between regular parameters and
*args in function definitions.Consider how many arguments each can take.
You got /3 concepts.