PCEP Computer Programming and Python Fundamentals Practice Question
A programmer is debugging a Python script that is supposed to concatenate a user's first and last names with a space between them. The code is: first = 'John' last = 'Doe' full = first + ' ' + last print(full) What is the output of this script?
⚠ Common exam trap
The trap here is overlooking the explicit space string or thinking that concatenation requires a special method rather than the + operator.
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
✓
John Doe
The + operator concatenates strings. The expression first + ' ' + last evaluates to 'John' + ' ' + 'Doe', which is 'John Doe'. The print function then displays that string. The other options misinterpret the space, the quotes, or the validity of string concatenation.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
John' 'Doe
Why it's wrong here
This would be the output if the quotes around the space were printed literally, but they are not. In Python, quotes delimit string literals and are not part of the string value. The space character itself is concatenated, so the output is without visible quotes.
- ✗
JohnDoe
Why it's wrong here
This would be the result if the space character were omitted from the concatenation. The code includes ' ' between first and last, so a space is inserted. Therefore, the output includes a space, making 'JohnDoe' incorrect.
- ✗
An error occurs because you cannot concatenate strings with the + operator.
Why it's wrong here
The + operator is valid for string concatenation in Python. It combines two strings into a new string. There is no error here because both operands are strings. The code runs successfully and produces the concatenated result.
- ✓
John Doe
Why this is correct
The code concatenates the string 'John', a space, and 'Doe' using the + operator. The space is a string literal ' ' and is included between the two names. The resulting string is 'John Doe', which is then printed. This is the correct output.
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.