2024-04-29 07:05:22 发布
网友
如何通过撇号'和-拆分字符串?
'
-
例如,给定string = "pete - he's a boy"
string = "pete - he's a boy"
这感觉有点老套,但你可以:
string.replace("-", "'").split("'")
string = "pete - he's a boy" result = string.replace("'", "-").split("-") print result ['pete ', ' he', 's a boy']
可以使用正则表达式模块的拆分函数:
re.split("['-]", "pete - he's a boy")
这感觉有点老套,但你可以:
可以使用正则表达式模块的拆分函数:
相关问题 更多 >
编程相关推荐