PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
A junior developer writes: print('Hello' + 5). This code raises an error. What is the best way to fix it?
⚠ Common exam trap
Python Institute often tests the distinction between concatenation (`+`) and multiple arguments in `print()`, where candidates may think `print('Hello', 5)` produces `Hello5` instead of `Hello 5` due to the default `sep=' '` parameter.
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
✓
print('Hello' + str(5))
Python's `+` operator for strings requires both operands to be strings. The code `print('Hello' + 5)` raises a `TypeError` because it attempts to concatenate a string with an integer. Using `str(5)` converts the integer to the string `'5'`, allowing the concatenation to succeed and print `Hello5`.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
print('Hello' * 5)
Why it's wrong here
Repeats 'Hello' 5 times, not concatenation.
- ✓
print('Hello' + str(5))
Why this is correct
Converts integer 5 to string and concatenates.
- ✗
print('Hello', 5)
Why it's wrong here
Prints two separate items with a space, not concatenation.
- ✗
print('Hello' + '5')
Why it's wrong here
This works but changes the value to string '5', not the integer.
Go deeper
Related to this question
About these practice questions
One of 498 original PCEP practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. 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.