PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions
A function is defined as: def func(*args, **kwargs): print(args, kwargs). It is called as func(1, 2, a=3, b=4). What is printed?
⚠ Common exam trap
Python Institute often tests the distinction between `*args` (tuple) and `**kwargs` (dictionary), and the trap here is that candidates mistakenly think keyword arguments are included in the tuple or that `*args` produces a list, leading them to pick options A or D.
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
✓
(1, 2) {'a': 3, 'b': 4}
The function uses `*args` to capture positional arguments into a tuple and `**kwargs` to capture keyword arguments into a dictionary. When called as `func(1, 2, a=3, b=4)`, `args` becomes `(1, 2)` and `kwargs` becomes `{'a': 3, 'b': 4}`, so `print(args, kwargs)` outputs `(1, 2) {'a': 3, 'b': 4}`. Option B is correct because it matches this exact output.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
(1, 2, a=3, b=4)
Why it's wrong here
Positional arguments 1 and 2 are packed into the args tuple, while a=3 and b=4 are packed into the kwargs dictionary; they are not merged into one tuple. It is tempting because the call syntax looks like a single argument list, but *args and **kwargs collect separately.
- ✓
(1, 2) {'a': 3, 'b': 4}
Why this is correct
Positional arguments 1 and 2 are collected into the args tuple, while keyword arguments a=3 and b=4 are collected into the kwargs dictionary. Printing both objects therefore yields the tuple (1, 2) followed by the dictionary {'a': 3, 'b': 4}.
- ✗
TypeError
Why it's wrong here
The signature accepts any number of positional and keyword arguments, so func(1, 2, a=3, b=4) binds cleanly without error. It is tempting because mixing positional and keyword arguments often raises TypeError, but that occurs only when arguments collide with named parameters, which *args and **kwargs avoid.
- ✗
[1, 2] {'a': 3, 'b': 4}
Why it's wrong here
*args always produces a tuple, never a list, so the first printed value is (1, 2). It is tempting because square brackets are common for collections, but only **kwargs yields a dictionary; the positional collector is immutable and tuple-typed.
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.