Courseiva

PCEP Computer Programming and Python Fundamentals Practice Question

A student types the following into a Python 3 interactive session:

>>> greeting = 'Hello' >>> greeting = greeting + ' World' >>> print(greeting)

What is displayed?

⚠ Common exam trap

The trap here is assuming that reassigning a string variable modifies the original string object instead of creating a new one and rebinding the name.

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

The second statement evaluates the right-hand side first: greeting still refers to 'Hello', so 'Hello' + ' World' produces a new string containing the space, and the name greeting is rebound to that value. The subsequent print call therefore outputs the combined text. Because str objects are immutable, reassignment replaces the reference rather than altering the original object in place.

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

    Why it's wrong here

    This would be the output only if the second assignment never executed or raised an error before rebinding the name. The concatenation greeting + ' World' succeeds because both operands are strings, so greeting is reassigned and the earlier value is discarded. The old binding is no longer referenced by that name.

  • ✗

    HelloWorld

    Why it's wrong here

    This result would appear only if the space character were omitted from the literal. The literal ' World' begins with a space, and the + operator joins strings exactly as written with no separator inserted automatically. Python does not trim or add whitespace during concatenation, so the space is preserved in the result.

  • ✓

    Hello World

    Why this is correct

    The name greeting is first bound to the string 'Hello'. The assignment greeting = greeting + ' World' concatenates the two strings and rebinds the name to the new string 'Hello World'. print then displays that value. Strings are immutable, so a new string object is created rather than modifying the original.

  • ✗

    A TypeError is raised

    Why it's wrong here

    Concatenating two str objects with + is fully supported and returns a new str. A TypeError would occur only if one operand were a different type, such as an int, because Python 3 does not implicitly convert numbers to text. Both operands here are string literals, so the operation completes normally.

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 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.