ProgrammingModerateTCS NQT · Accenture

What is printed?

What is printed?
s = 'hello'
try:
    s[0] = 'j'
except TypeError:
    print('immutable')
t = s.replace('h', 'j')
print(t, s)
  1. A. immutable | jello hello
  2. B. jello hello
  3. C. immutable | hello hello
  4. D. TypeError | jello hello

Correct answer: A. immutable | jello hello

Strings cannot be changed in place, so item assignment raises TypeError. replace returns a new string and leaves s unchanged.

More Python Programming questions

Exams that ask this topic