获取python中两个特定字符之间的子字符串

时间:2015-03-16 08:33:31

标签: python string special-characters

我真的很困惑,无法为我编写代码。 看这是我的字符串:

  

a ="你好|我的朋友们在|堆栈|结束|流"

我想打印#34;我的朋友"介于第一和第二之间" |" 请帮帮我

1 个答案:

答案 0 :(得分:0)

您可以使用string.split功能。

>>> a="hello | my friends| in | stack | over | flow"
>>> a.split('|')[1].strip()
'my friends'

a.split('|')[1]从列表中打印索引1处的元素,该列表是根据|分割输入而创建的。

相关问题