String in python is immutable object. Immutable object’s value can not be changed. In case of replacing character of a string , It create a new string after replacing the characters.
Here is what you are looking for :
For Example, replacing “H” with “Y” in “Hello World” returns “Yello World”
phrase ="Hello World"converted_list =list(phrase)
# replacing H with Yconverted_list[0] ="Y"phrase ="".join(converted_list)
print(phrase)
# replacing W with Hconverted_list[6] ="H"phrase ="".join(converted_list)
print(phrase)
Sharing is caring!