相关疑难解决方法(0)

使用Python替换多个字符

我需要更换一些字符如下:&- > \&,#- > \#,...

我编码如下,但我想应该有更好的方法.任何提示?

strs = strs.replace('&', '\&')
strs = strs.replace('#', '\#')
...
Run Code Online (Sandbox Code Playgroud)

python string replace

158
推荐指数
8
解决办法
31万
查看次数

在Python中有效地执行多个字符串替换

如果我想进行多个字符串替换,那么最有效的方法是什么呢?

我旅行中遇到的一种情况如下:

>>> strings = ['a', 'list', 'of', 'strings']
>>> [s.replace('a', '')...replace('u', '')  for s in strings if len(s) > 2]
['a', 'lst', 'of', 'strngs']
Run Code Online (Sandbox Code Playgroud)

python string immutability

8
推荐指数
1
解决办法
5184
查看次数

标签 统计

python ×2

string ×2

immutability ×1

replace ×1