gpt4 book ai didi

python - 在第一次出现时拆分

转载 作者:IT老高 更新时间:2023-10-28 12:10:37 24 4
gpt4 key购买 nike

在第一次出现分隔符时拆分字符串的最佳方法是什么?

例如:

"123mango abcd mango kiwi peach"

拆分第一个 mango 得到:

"abcd mango kiwi peach"

最佳答案

来自 the docs :

str.split([<i>sep</i>[, <i>maxsplit</i>]])

Return a list of the words in the string, using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done (thus, the list will have at most maxsplit+1 elements).

s.split('mango', 1)[1]

关于python - 在第一次出现时拆分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6903557/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com