Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python split string by specific word

>>> mary = 'Mary had a little lamb'
>>> mary.split('a')                 # splits on 'a'
['M', 'ry h', 'd ', ' little l', 'mb'] 
>>> hi = 'Hello mother,
Hello father.'
>>> print(hi)
Hello mother,
Hello father. 
>>> hi.split()                # no parameter given: splits on whitespace
['Hello', 'mother,', 'Hello', 'father.'] 
>>> hi.split('
')                 # splits on '
' only
['Hello mother,', 'Hello father.']
Source by sites.pitt.edu #
 
PREVIOUS NEXT
Tagged: #python #split #string #specific #word
ADD COMMENT
Topic
Name
9+7 =