Question Detail

COS 102 Python strings Objective Question

Question

What is the primary reason the + operator does not automatically add spaces when concatenating strings?
Options
A Python optimizes for memory efficiency, avoiding unnecessary space characters.
B It provides greater control to the programmer over string formatting and spacing.
Correct Answer
C Spaces are only added when concatenating strings with numbers.
D The <code>+</code> operator is primarily for mathematical addition, not string manipulation.
Correct Answer

Option B is the correct answer.

Detailed Explanation

The document states, 'The + operator does not add spaces automatically. You must add them yourself!' This design choice gives the programmer explicit control over every character in the resulting string, allowing for precise formatting whether spaces are desired or not.

Hint

Consider the benefit of having explicit control over string content versus automatic behavior.

Question Info