Mon*_*lal 3 python string split
如果一个字符串命中https(没有空格)怎么能把它分成两个单词呢?例如,Join us!https://t.co/Fe0oTahdom
想要使它像Join us!
和https://t.co/Fe0oTahdom
读取帐户指数
s = 'Join us!https://t.co/Fe0oTahdom'
[s[0:s.index('https')], s[s.index('https'):]]
Run Code Online (Sandbox Code Playgroud)
如果您只想拆分https
关键字,最简单的方法
myString = 'Join us!https://t.co/Fe0oTahdom'
(head, sep, tail) = myString.partition('https')
print head #Prints Join us!
print sep + tail #Prints the rest
Run Code Online (Sandbox Code Playgroud)