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
This expects a single dictionary argument, not keyword arguments.
- ✓
def func(**kwargs):
Why this is correct
Correct: **kwargs accepts arbitrary keyword arguments.
- ✗
def func(**args):
Why it's wrong here
While syntactically valid, by convention **kwargs is used; **args would collect keyword arguments but the parameter name is not the issue; however, the question expects **kwargs as correct pattern.
- ✗
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 498-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.