In Python, strings are immutable.
What is the standard idiom to walk through a string character-by-character and modify it?
The only methods I can think of are some genuinely stanky hacks related to joining against a result string.
--
In C:
for(int i = 0; i < strlen(s); i++)
{
s[i] = F(s[i]);
}
This is super expressive and says exactly what I am doing. That is what I am looking for.

本文探讨了如何在Python中逐字符遍历并修改字符串的方法。由于Python中的字符串是不可变的,文章介绍了几种常见且高效的替代方案,包括使用列表推导式、map函数以及可变类型如bytearray。

1449







replacefor this? – S.Lott Aug 12 '10 at 2:43