Question Detail

COS 102 Advanced Text Processing Objective Question

Question

When a Python string method like `.upper()` is called on a string, what is the effect on the original string variable?
Options
A The original string is directly modified in place.
B The method creates and returns a brand new string value.
Correct Answer
C The original string is deleted, and a new one is created only if assigned to a variable.
D It raises a `TypeError` because strings are immutable.
Correct Answer

Option B is the correct answer.

Detailed Explanation

The document clarifies: 'String methods don't modify the original text—they return a brand new string value that you have to save into a variable.' This is a direct consequence of strings being immutable.

Hint

Since strings are immutable, methods must create new strings instead of changing existing ones.

Question Info