2024-10-03 02:37:37 发布
网友
我想使用python将"Onehundredthousand"拆分为"one""hundred""thousand"。 我该怎么做?你知道吗
"Onehundredthousand"
"one"
"hundred"
"thousand"
使用正则表达式^{}。如果使用捕获的组作为分隔符,它也将包含在结果列表中:
>>> import re >>> re.split('(hundred)', 'Onehundredthousand') ['One', 'hundred', 'thousand']
>>> s = "Onehundredthousand" >>> s.replace('hundred', '_hundred_').split('_') ['One', 'hundred', 'thousand']
这只适用于给定的字符串。你知道吗
可以使用字符串的partition方法将其拆分为3部分(左部分、分隔符、右部分):
partition
"onehundredthousand".partition("hundred") # output: ('one', 'hundred', 'thousand')
使用正则表达式^{} 。如果使用捕获的组作为分隔符,它也将包含在结果列表中:
这只适用于给定的字符串。你知道吗
可以使用字符串的
partition
方法将其拆分为3部分(左部分、分隔符、右部分):相关问题 更多 >
编程相关推荐