Skip to main content

str.split()

str.split(separator)

Splits a string into a list. You can specify the separator, default separator is any whitespace.

Input:
separator : String, optional (Default is whitespace " ")
Specifies the separator to use when splitting the string.
Returns:
A list object of the separated string.
Return Type:
array

txt = "I like potato, wanna mash my potato, won't you mash your potato with me?"
txt.split()

['I', 'like', 'potato,', 'wanna', 'mash', 'my', 'potato,', "won't", 'you', 'mash', 'your', 'potato', 'with', 'me?']

txt = "Split#By#Delimiter"
txt.split("#")

['Split', 'By', 'Delimiter']


Problems or suggestions about this page? Fill out our feedback form.