Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取python中两个特殊字符之间的子字符串_Python_String_Special Characters - Fatal编程技术网

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

获取python中两个特殊字符之间的子字符串,python,string,special-characters,Python,String,Special Characters,我真的很困惑,不能为我编写这样的代码。 看,这是我的绳子: a=“你好|我的朋友们|在|栈|在|流” 我想打印第一个和第二个“|”之间的“我的朋友” 请帮助我您可以使用string.split函数 >>> a="hello | my friends| in | stack | over | flow" >>> a.split('|')[1].strip() 'my friends' a.split(“|”)[1]从列表中打印索引1处的元素,该列表是通过根据a

我真的很困惑,不能为我编写这样的代码。 看,这是我的绳子:

a=“你好|我的朋友们|在|栈|在|流”

我想打印第一个和第二个“|”之间的“我的朋友”
请帮助我

您可以使用
string.split
函数

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

a.split(“|”)[1]
从列表中打印索引1处的元素,该列表是通过根据
a.split(“|”)
分割输入而创建的?a、 split(“|”)[0]。split(“|”)[1]没有回答这个问题。非常感谢,先生