Courseiva

PCEP Computer Programming and Python Fundamentals Practice Question

Which THREE of the following code snippets will successfully print the string 'Hello, World!'? (Choose three.)

⚠ Common exam trap

The PCEP exam often tests the distinction between string delimiters and the need for escaping quotes, trapping candidates who assume that any quote pair can contain the same quote character without escaping.

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, World!''')

Option A is correct because triple-quoted strings ('''...''') are valid Python string literals, and since the content 'Hello, World!' contains no conflicting triple quotes, print('''Hello, World!''') outputs the string successfully. Option C is correct because a double-quoted string literal "Hello, World!" is valid Python syntax, and print("Hello, World!") outputs the exact text. Option E is correct because a single-quoted string literal 'Hello, World!' is valid Python syntax, and print('Hello, World!') outputs the exact text. Option B is incorrect because the inner double quotes around Hello! terminate the string early, causing a SyntaxError. Option D is incorrect because the apostrophe in It's prematurely closes the single-quoted string, also causing a SyntaxError.

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, World!''')

    Why this is correct

    Triple-quoted strings are valid Python string literals, so `'''Hello, World!'''` creates the same str object as single or double quotes and passes it to `print()`. The embedded apostrophe-free content needs no escaping, and the statement satisfies the stem's requirement to output exactly `Hello, World!`.

  • ✗

    print("He said, "Hello!"")

    Why it's wrong here

    The inner double quotes terminate the string literal, leaving Hello! as stray tokens, so a SyntaxError occurs. It is tempting because embedding quoted speech inside a print call looks natural, and it would work if the inner quotes were single quotes or escaped.

  • ✓

    print("Hello, World!")

    Why this is correct

    The built-in `print()` function writes its argument to standard output, appending a newline by default. Passing the string literal `"Hello, World!"` directly satisfies the stem's requirement to output that exact text, so this snippet succeeds without needing variables, concatenation, or formatting.

  • ✗

    print('It's a beautiful day')

    Why it's wrong here

    The apostrophe in It's closes the single-quoted literal, so the remaining characters raise a SyntaxError. It is tempting because apostrophes inside printed text are ordinary English, and the snippet would work if the string used double quotes or an escaped apostrophe.

  • ✓

    print('Hello, World!')

    Why this is correct

    The built-in `print()` function writes its argument to standard output, appending a newline by default, so the string literal `'Hello, World!'` is emitted exactly as written. This satisfies the stem's requirement that the snippet successfully print that string, with no syntax error or missing quotation marks.

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 →

How Courseiva writes practice questions · Editorial policy

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.