PCEP Computer Programming and Python Fundamentals Practice Question
A programmer wants to create a function that can accept any number of keyword arguments and store them in a dictionary. Which function definition is correct?
⚠ Common exam trap
The PCEP exam often tests the distinction between *args (positional arguments packed into a tuple) and **kwargs (keyword arguments packed into a dictionary), and the trap here is that candidates confuse the single asterisk for keyword arguments or forget that the double asterisk is required for dictionary packing.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
def func(**kwargs):
The **kwargs parameter in a function definition collects any number of extra keyword arguments into a dictionary. The double asterisk (**) is the Python syntax for capturing keyword arguments, and 'kwargs' is the conventional name for the resulting dictionary.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
def func(kwargs):
Why it's wrong here
A single named parameter accepts exactly one positional argument and stores it directly, not a dictionary of arbitrary keyword arguments. It tempts because kwargs is the conventional name for the keyword-collection parameter, but the missing double asterisk means no packing occurs.
- ✓
def func(**kwargs):
Why this is correct
The double-asterisk prefix **kwargs in a parameter list collects arbitrary keyword arguments into a dictionary named kwargs, satisfying the stem's requirement to accept any number of keyword arguments. Single-asterisk *args would instead gather positional arguments into a tuple, which does not meet the stated constraint.
- ✗
def func(**args):
Why it's wrong here
This definition is actually correct for the scenario, so it cannot be the intended incorrect option; **args does gather arbitrary keyword arguments into a dictionary named args. It is tempting precisely because it matches the requirement, meaning the stem's expected answer must be a different option.
- ✗
def func(*kwargs):
Why it's wrong here
*kwargs collects positional arguments into a tuple, not keyword.
Go deeper
Related to this question
About these practice questions
This PCEP question is part of Courseiva's 482-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This PCEP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCEP exam.