Modify one character in a string

Paul Rubin http
Thu May 25 19:16:24 CEST 2006

Larry Bates <larry.bates at> writes:
> IMHO the most elegant method is something like:
> def switchchar(srcstring, position, character):
>     b=list(srcstring)
>     b[2]=character
>     return ''.join(b)

If the strings or large or you're doing it a lot, the array module is
likely more efficient.

More information about the Python-list mailing list