在python3中从字符串中删除某些字符

2024-06-08 17:06:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个字符串bp,它被设置为

s1 = '[\'<li class="list__item">Accommodates most miter saws; free adapter brackets ' \
'for offset mounting holes with holes included</li>\', \'<li class="list__item">' \
'Trigger handle quick release tool mounts for mounting or removing miter saw ' \
'quickly and easily</li>\', \'<li class="list__item">Adjustable arms extend out to ' \
'provide 116 in. of material support</li>\', \'<li class="list__item">Fast and easy ' \
'setup with snap pin lock folding legs</li>\', \'<li class="list__item">Easy height ' \
'adjustment of material supports with no tools required</li>\', \'<li ' \
'class="list__item">Stand collapses down quickly for easy storage and transport</li>\', ' \
'\'<li class="list__item">20 in. quick attach tool mounts may be used as miter saw base ' \
'on most surfaces</li>\', \'<li class="list__item">Durable powder-coated finish</li>\', ' \
'\'<li class="list__item">Includes: folding portable miter saw stand and operator ' \
' manual</li>\', \'<li class="list__item">90-day returnable</li>\']'

我要删除所有“[\”和\以及逗号 我有办法做到吗?你知道吗


Tags: andmostforwithlitoolquickitem
1条回答
网友
1楼 · 发布于 2024-06-08 17:06:33

你没有说用什么来替换它们,所以我用空字符串来替换它们

#!python3

s1 = '[\'<li class="list__item">Accommodates most miter saws; free adapter brackets ' \
'for offset mounting holes with holes included</li>\', \'<li class="list__item">' \
'Trigger handle quick release tool mounts for mounting or removing miter saw ' \
'quickly and easily</li>\', \'<li class="list__item">Adjustable arms extend out to ' \
'provide 116 in. of material support</li>\', \'<li class="list__item">Fast and easy ' \
'setup with snap pin lock folding legs</li>\', \'<li class="list__item">Easy height ' \
'adjustment of material supports with no tools required</li>\', \'<li ' \
'class="list__item">Stand collapses down quickly for easy storage and transport</li>\', ' \
'\'<li class="list__item">20 in. quick attach tool mounts may be used as miter saw base ' \
'on most surfaces</li>\', \'<li class="list__item">Durable powder-coated finish</li>\', ' \
'\'<li class="list__item">Includes: folding portable miter saw stand and operator ' \
' manual</li>\', \'<li class="list__item">90-day returnable</li>\']'

s1 = s1.replace("[", "").replace("\\", "").replace(",", "").replace("]", "")

print(s1)

相关问题 更多 >