2 python string special-characters
我真的很困惑,无法编写为我执行此操作的代码。看这是我的字符串:
a="你好 | 我的朋友们 | in | stack | over | flow"
我想打印第一个和第二个“|”之间的“我的朋友” 请帮我
你可以使用string.split函数。
>>> a="hello | my friends| in | stack | over | flow"
>>> a.split('|')[1].strip()
'my friends'
Run Code Online (Sandbox Code Playgroud)
a.split('|')[1]从列表中打印索引 1 处的元素,该列表是通过根据 分割输入而创建的|。