首页 > 解决方案 > 使用字符串分隔符拆分字符串,并将数据与分隔符一起显示

问题描述

我需要获取字符串列表以及分隔符例如

string= "I am a developer and i need to work on web development"

我在用

re.split("and", string)```

I need to get Output as
**Output**
```I am developer 
and i need to work on web development```

标签: pythonsplit

解决方案


尝试这个:

>>> s = "I am a developer and i need to work on web development"
>>> s1 = s.replace('and', '\nand')
>>> s1
'I am a developer \nand i need to work on web development'
>>> print(s1)
I am a developer 
and i need to work on web development
>>> 

推荐阅读