message = "sea you soon"
message[2] = "e"
print(message)
o/p: TypeError: 'str' object does not support it
In this string I wanted to change particular index can you give some clue how to resolve it
message = "sea you soon"
message[2] = "e"
print(message)
o/p: TypeError: 'str' object does not support it
In this string I wanted to change particular index can you give some clue how to resolve it
For further actions, you may consider blocking this person and/or reporting abuse
Chirag Sagar -
Michael Linson -
0x3d Site -
PRANTA Dutta -
Top comments (3)
Hey Asish, in Python string objects are inmutable, you need to create a new string
if i wanted to replace it that is it possible
Short answer as mentioned by Kevin, is “no”.
The long answer is you can create a new string based on the existing string.
In the above example I used an f-string to make the new string, but it’s not the only option.
The
message[0:2]
gives you “se” and themessage[3:]
gives you “ you soon”. These expressions are called slices in Python.