Courseiva
Strings →easyMultiple Choice

PCAP Strings Practice Question

A beginner programmer writes: name = "Alice"; print("Hello " + name). Which string method alternative is more efficient and recommended for Python 3?

⚠ Common exam trap

Python Institute often tests the distinction between older formatting methods (%-formatting and str.format()) and the modern f-string syntax, trapping candidates who think any valid method is equally recommended, when in fact f-strings are the preferred and most efficient choice in Python 3.6+.

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(f"Hello {name}")

F-strings (formatted string literals) are the most efficient and readable string formatting method introduced in Python 3.6. They evaluate expressions at runtime and directly interpolate variables into the string, avoiding the overhead of method calls or the older %-formatting, making them both faster and more Pythonic.

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 {}".format(name))

    Why it's wrong here

    The `str.format()` method substitutes the value of `name` into the `{}` placeholder, which is valid and more flexible than `%` formatting, but it is needlessly verbose for simple interpolation. Because the template string is parsed and processed at runtime, it is less efficient than an f-string, and the explicit method call makes the code longer without adding clarity. It remains a useful tool for complex formatting (e.g., reuse of arguments, named fields), but for this beginner case it is not the most recommended approach.

  • ✗

    print("Hello %s" % name)

    Why it's wrong here

    `%`-formatting is Python's legacy C-style formatting operator. Here, `%s` is a conversion specifier that expects the value of `name` to be supplied as a single argument or a tuple. While it works, it has several drawbacks: the `%` operator performs its own parsing overhead, the syntax is less readable than modern alternatives, and it does not automatically handle calls like `format()` or f-strings for embedded expressions. It is not the preferred choice in modern Python, especially when an f-string is clearer and just as concise.

  • ✓

    print(f"Hello {name}")

    Why this is correct

    An f-string (formatted string literal) is the recommended and most idiomatic way to embed `name` directly into the string. The expression inside `{}` is evaluated at runtime using the current scope, so `f"Hello {name}"` precisely reads as 'Hello, followed by the value of `name`'. This approach is concise, readable, and avoids the overhead of a separate method call or operator, making it both efficient and Pythonic. Since Python 3.6, f-strings are the preferred method for most string formatting tasks.

  • ✗

    print("Hello " + name) is fine

    Why it's wrong here

    String concatenation with `+` is semantically correct for this example, but it is not the best choice in modern Python. Each `+` operation creates a brand-new intermediate string object, which can be inefficient—especially if done repeatedly in a loop—because the entire resulting string is copied each time. It also becomes unwieldy when formatting multiple values or non-string types, as you must manually convert and arrange pieces. For these reasons, concatenation is considered less readable and less efficient, and f-strings are strongly preferred.

About these practice questions

Courseiva writes every PCAP question from scratch — 421 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 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.