+ 1
Reassign problem
Is it possible to reassign a letter in a string? Like: str='work' I want to replace k with d, but str='work' str[3]=d is not working. Is there any other useful way?
2 Antworten
+ 3
strings are not mutable (i.e. cannot be changed) in Python. One approach could be: turn the string into a list, then change the list, and finally use 'join' to turn the list back into a string.
+ 1
you can use somestring=somestring.replace (oldchar, newchar)