首页 > 解决方案 > 如何从 Python 中的字符串数组中删除正斜杠?

问题描述

我有一个这样的数组

arrayOne = ['["https:\/\/somewebsite.com"]','["https:\/\/anotherwebsite.com"]', '["https:\/\/lastwebsite.com"]']

本质上,我要做的是\从上面数组中的字符串中删除正斜杠。我是python初学者,所以我边走边学。python中有没有可以做到这一点的方法?我正在使用python 3.9。

成功的输出如下所示:

arrayTwo = ['["https://somewebsite.com"]','["https://anotherwebsite.com"]', '["https://lastwebsite.com"]']

任何指导都会有所帮助!

非常感谢!

标签: python

解决方案


您可以对字符串对象使用替换方法。然后对数组中的每个 web url 使用列表理解。

arrayOne = [each.replace("\\","") for each in arrayOne]

推荐阅读