按'和-分割字符串
如何通过撇号 '
和 -
来分割字符串?
举个例子,给定
string = "pete - he's a boy"
6 个回答
2
这听起来有点不太正规,但你可以这样做:
string.replace("-", "'").split("'")
9
string = "pete - he's a boy"
result = string.replace("'", "-").split("-")
print result
['pete ', ' he', 's a boy']
当然可以!请把你想要翻译的内容发给我,我会帮你用简单易懂的语言解释清楚。
19
你可以使用正则表达式模块里的 split 函数:
re.split("['-]", "pete - he's a boy")