Junior — Middle
Can a string be considered a mutable data type?
sobes.tech AI
Answer from AI
In Python, a string (str) is an immutable data type. This means that once a string is created, its contents cannot be changed. Any operations that seem to modify the string actually create a new string. For example:
s = "hello"
s = s.replace('h', 'H') # a new string "Hello" is created
The original string "hello" remains unchanged, and the variable s now refers to the new string.