PCEP Practice Question: Functions, Tuples, Dictionaries and Exceptions
A developer uses a tuple to store immutable configuration data: config = ('localhost', 8080, True). They then write: host, port, secure = config. What is the result of this statement?
⚠ Common exam trap
The trap here is assuming that tuple unpacking requires parentheses or that it fails if the tuple contains mixed types.
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
✓
host becomes 'localhost', port becomes 8080, and secure becomes True.
Tuple unpacking assigns each element of the tuple to the corresponding variable on the left side, in order. The number of variables must equal the number of elements. In this case, three variables match three elements, so host, port, and secure receive 'localhost', 8080, and True respectively. No error occurs.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
host becomes 'localhost', port becomes 8080, and secure becomes True.
Why this is correct
Tuple unpacking assigns the first element to host, the second to port, and the third to secure, in order. The tuple has exactly three elements, matching the three target variables. This is a concise way to extract multiple values from a tuple. The operation succeeds without error, and the variables receive the corresponding values from the tuple.
- ✗
A SyntaxError occurs because the left side must be enclosed in parentheses.
Why it's wrong here
Parentheses around the target variables are optional in tuple unpacking. The statement host, port, secure = config is syntactically valid. A SyntaxError would occur if the left side were malformed, such as using invalid variable names or missing commas. This option misunderstands Python's syntax rules for multiple assignment, which allow omitting parentheses.
- ✗
A ValueError is raised because tuples cannot be unpacked into multiple variables.
Why it's wrong here
Tuple unpacking is a standard Python feature that allows assigning each element of a tuple to a separate variable in a single statement. It requires the number of variables on the left to match the number of elements in the tuple. Here, three variables match three elements, so no error occurs. This option incorrectly claims that tuple unpacking is invalid, which is not true.
- ✗
host becomes the entire tuple, and port and secure are assigned None.
Why it's wrong here
This option describes a behavior that does not exist in Python. When unpacking, each variable on the left receives one element from the iterable on the right. There is no partial assignment or default None for missing variables. The number of variables must match the number of elements, or a ValueError is raised. Here, the match is exact, so all three variables get values.
Go deeper
Related to this question
About these practice questions
Courseiva writes every PCEP question from scratch — 482 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official Python Institute exam blueprint
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.