Python *args and **kwargs MCQs – Multiple Choice Questions for Practice and Learning
Test your understanding of Python *args and **kwargs with these multiple choice questions. Practice function arguments, flexible parameters, and advanced function concepts with beginner-friendly MCQs and detailed answers. Ideal for students and Python learners.
Topic: args-kwargs
📝 Multiple Choice Questions
🟢 Beginner
Q1. What is the type of the variable that collects positional arguments when using `*args` in a Python function?
🟢 A. list
🔵 B. tuple
🟠 C. dict
🔴 D. set
Answer
tuple
`*args` collects all extra positional arguments into a tuple inside the function.
Q2. What does `**kwargs` collect inside a Python function?
🟢 A. a list of positional arguments
🔵 B. a tuple of positional arguments
🟠 C. a dictionary of keyword arguments
🔴 D. a set of keyword arguments
Answer
a dictionary of keyword arguments
`**kwargs` collects all extra keyword arguments into a dictionary inside the function.
Q3. Which symbol is used to define `*args` in a Python function?
🟢 A. *
🔵 B. **
🟠 C. &
🔴 D. #
Answer
*
The single asterisk `*` is used to collect positional arguments.
Q4. Which symbol is used to define `**kwargs` in a Python function?
🟢 A. *
🔵 B. **
🟠 C. &
🔴 D. ##
Answer
**
The double asterisk `**` is used to collect keyword arguments into a dictionary.
🟡 Intermediate
Q1. What is the output of the following code?
def test(*args):
return args
print(test(1, 2, 3))
🟢 A. [1, 2, 3]
🔵 B. (1, 2, 3)
🟠 C. {1: 2, 3: None}
🔴 D. Error
Answer
(1, 2, 3)
`*args` packs the arguments into a tuple, so the output is (1, 2, 3).