Question Detail

COS 102 Advanced Text Processing Objective Question

Question

What is the recommended modern Python feature for dynamically injecting values into strings?
Options
A String concatenation using the '+' operator.
B The `str.format()` method.
C f-strings (Formatted String Literals).
Correct Answer
D Template strings using `string.Template`.
Correct Answer

Option C is the correct answer.

Detailed Explanation

The document states: 'Modern Python uses f-strings (Formatted String Literals) to easily embed variables inside strings.' It also mentions old concatenation is 'clunky and error-prone'.

Hint

The name of the chapter section provides the direct answer.

Question Info