gpt4 book ai didi

python - 如何在python中的特定字符后拆分字符串

转载 作者:太空宇宙 更新时间:2023-11-04 07:30:24 27 4
gpt4 key购买 nike

如果我有一个字符串,让我们说,b a hello b Hi,我如何将字符串拆分为所有 b AFTER字母 a 的第一次出现?

例如,它将返回 ["b a hello", "Hi"]

最佳答案

此处记录:str.rsplit()

sentence = 'b a hello b Hi'
sentence.rsplit('b', 1)

关于python - 如何在python中的特定字符后拆分字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48959833/

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