📌  相关文章
📜  python 按特定单词拆分字符串 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:08.377000             🧑  作者: Mango

代码示例3
>>> mary = 'Mary had a little lamb'
>>> mary.split('a')                 # splits on 'a'
['M', 'ry h', 'd ', ' little l', 'mb'] 
>>> hi = 'Hello mother,\nHello father.'
>>> print(hi)
Hello mother,
Hello father. 
>>> hi.split()                # no parameter given: splits on whitespace
['Hello', 'mother,', 'Hello', 'father.'] 
>>> hi.split('\n')                 # splits on '\n' only
['Hello mother,', 'Hello father.']