Courseiva
Strings →easyMultiple Choice

PCAP Strings Practice Question

Which of the following expressions returns the string 'Hello' repeated three times?

⚠ Common exam trap

Watch out — candidates often think the + operator can coerce types or that string multiplication accepts any numeric type, but Python strictly requires an integer for the repetition count and raises a TypeError for floats or strings.

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' * 3

In Python, the multiplication operator (*) when used with a string and an integer performs string repetition. 'Hello' * 3 returns the string 'HelloHelloHello' by concatenating three copies of the original string. This is a core feature of Python's sequence protocol, where strings are sequences of characters.

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' * 3

    Why this is correct

    In Python, the * operator, when applied to a string and an integer, performs sequence repetition. Because 3 is an int, 'Hello' * 3 creates a new string by joining three sequential copies of the original 'Hello', yielding exactly 'HelloHelloHello'. This is valid string repetition that works for any string and any non-negative integer, and it returns a single string object, not a tuple or list.

  • ✗

    'Hello' + 3

    Why it's wrong here

    The + operator is overloaded for strings to mean concatenation, but both operands must be of type str. In this expression, 3 is an int, and Python makes no implicit conversion of the integer to a string before attempting the operation. The result is a TypeError with a message such as "can only concatenate str (not 'int') to str", because the language design deliberately avoids guessing the programmer's intent with mixed-type additions.

  • ✗

    'Hello' * '3'

    Why it's wrong here

    For string repetition, the multiplier must be an integer; a string like '3' is a sequence, not a numeric type. Even though '3' visually contains a digit, Python does not implicitly parse it into an integer for use as a repetition count. Attempting 'Hello' * '3' triggers a TypeError: can't multiply sequence by non-int of type 'str', because the * operator has no defined behavior for a sequence multiplied by another sequence.

  • ✗

    'Hello' * 3.0

    Why it's wrong here

    Although 3.0 is numerically equal to 3, the multiplication operator for strings requires an integer as the right operand, not a float. Python's design does not perform implicit narrowing of a float to an int for sequence repetition, so it raises a TypeError: can't multiply sequence by non-int of type 'float'. Even a float like 3.0 that represents a whole number is rejected, because floats can carry fractional values and the language avoids making a potentially lossy conversion implicitly.

About these practice questions

This PCAP question is part of Courseiva's 421-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Same concept, more angles

1 more way this is tested on PCAP

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 result of the expression 'Hello' * 3?

easy
  • A.'Hello3'
  • ✓ B.'HelloHelloHello'
  • C.'Hello Hello Hello'
  • D.TypeError

Why B: In Python, the multiplication operator (*) on a string repeats the string a specified number of times. 'Hello' * 3 concatenates 'Hello' three times, producing 'HelloHelloHello'. This is a fundamental string operation defined in Python's sequence protocol.

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This PCAP 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 PCAP exam.