PCEP Practice Question: Data Types, Variables, Basic I/O and Operators
What is the output of the following code?
print('Hello', 'World', sep='-', end='!\n')⚠ Common exam trap
The trap here is that candidates often overlook the `end` parameter override and assume the default newline-only ending, or they confuse `sep` with `end`, leading them to pick an option with a space separator or missing the exclamation mark.
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
✓
Hello-World!\n
The `print()` function with `sep='-'` replaces the default space separator with a hyphen between the two arguments 'Hello' and 'World', producing 'Hello-World'. The `end='!\n'` parameter overrides the default newline-only end with an exclamation mark followed by a newline, so the output ends with '!' before the newline. Therefore, the correct output is 'Hello-World!\n'.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Hello-World\n
Why it's wrong here
Missing '!' at the end
- ✓
Hello-World!\n
Why this is correct
Correct: 'Hello' and 'World' separated by '-', ending with '!' and newline
- ✗
Hello World!\n
Why it's wrong here
sep='-' is not applied
- ✗
Hello World!\n
Why it's wrong here
This is the default output without custom sep/end
Go deeper
Related to this question
About these practice questions
Courseiva writes every PCEP question from scratch — 498 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 →
Same concept, more angles
1 more way this is tested on PCEP
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. What is the output of the following code? ```python print('Hello', 'World', sep='-') ```
easy- A.HelloWorld
- B.Hello - World
- C.Hello World
- ✓ D.Hello-World
Why D: The `print()` function's `sep` parameter specifies the separator between multiple arguments. By default, `sep` is a space, but here it is explicitly set to `'-'`, so the output joins 'Hello' and 'World' with a hyphen, producing 'Hello-World'. Option D is correct because the hyphen is placed directly between the two strings without any extra spaces.
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.