Python 中的字符串或列表替换
我将如何获取一个字符串:
("h1", "h2", "h3, "h4")
并用数字 1, 2, 3, 4
替换这些值?
相应地,我如何在列表上执行相同的操作?
How would I go about taking a string:
("h1", "h2", "h3, "h4")
And substituting these values with numbers 1, 2, 3, 4
?
Correspondingly, how I would I preform the same operation but on a list instead?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果这就是你想要的。
还不太清楚;我假设您的输入实际上不是一个字符串
"(\"h1\", \"h2\", \"h3\", \"h4\")"
,而是一个列表字符串。我不确定你的第二个问题是什么意思,因为它似乎与第一个问题相同。
我会相应地更新我的答案=)
If this is what you want.
It's not exactly clear; I'm assuming that your input is not literally a string
"(\"h1\", \"h2\", \"h3\", \"h4\")"
, but a list of strings.And I'm not sure what you meant by your second question, as it appears to be the same as the first.
I will update my answer accordingly =)
这将删除每个非数字字符(不仅仅是
h
):或
This would strip out every non-numeric character (not only
h
):or