Courseiva

PCEP Computer Programming and Python Fundamentals Practice Question

A developer writes: print('Hello' + 5). What is the result?

⚠ Common exam trap

This exact scenario tests whether candidates understand that Python does not implicitly convert an integer to a string for concatenation, unlike loosely-typed languages.

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

✓

TypeError

In Python, the + operator performs string concatenation only when both operands are strings. Attempting to concatenate a string ('Hello') with an integer (5) raises a TypeError because Python does not implicitly convert the integer to a string for concatenation. This is a fundamental type safety feature of the language.

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 5

    Why it's wrong here

    Concatenating a string and an integer raises a TypeError, so nothing is printed; Python does not coerce the int to text. It tempts because print() accepts multiple comma-separated arguments and renders them space-separated, which is how 'Hello 5' is actually produced.

  • ✓

    TypeError

    Why this is correct

    Python's + operator on str requires both operands to be str; concatenating a str with an int raises TypeError rather than coercing the integer, because Python is strongly typed and defines no implicit int-to-str conversion for this operation.

  • ✗

    SyntaxError

    Why it's wrong here

    A SyntaxError arises when code violates Python's grammar, but `print('Hello' + 5)` parses cleanly — the failure occurs at runtime, when the `+` operator finds no valid concatenation between `str` and `int`. SyntaxError is tempting because mixing types feels like malformed code, and it would be correct for genuinely invalid syntax such as `print('Hello' 5)`.

  • ✗

    Hello5

    Why it's wrong here

    Python raises a TypeError because the + operator cannot concatenate str and int; it does not coerce the integer. The option tempts those expecting implicit conversion, as seen in JavaScript or Java's string concatenation. Explicit conversion, such as str(5) or an f-string, would produce "Hello5".

About these practice questions

One of 482 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 →

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.