Python String | split()
split() method in Python split a string into a list of strings after breaking the given string by the specified separator.
Syntax : str.split(separator, maxsplit)
Parameters :
separator : This is a delimiter. The string splits at this specified separator. If is not provided then any white space is a separator.maxsplit : It is a number, which tells us to split the string into maximum of provided number of times. If it is not provided then the default is -1 that means there is no limit.
Returns : Returns a list of strings after breaking the given string by the specified separator.
Example 1: Example to demonstrate how split() function works
text = 'geeks for geeks' # Splits at spaceprint(text.split()) word = 'geeks, for, geeks' # Splits at ','print(word.split(',')) word = 'geeks:for:geeks' # Splitting at ':'print(word.split(':')) word = 'CatBatSatFatOr' # Splitting at tprint(word.split('t')) |
Output :
['geeks', 'for', 'geeks'] ['geeks', ' for', ' geeks'] ['geeks', 'for', 'geeks'] ['Ca', 'Ba', 'Sa', 'Fa', 'Or']
Example 2: Example to demonstrate how split() function works when maxsplit is specified
word = 'geeks, for, geeks, pawan' # maxsplit: 0print(word.split(', ', 0)) # maxsplit: 4print(word.split(', ', 4)) # maxsplit: 1print(word.split(', ', 1)) |
Output :
['geeks, for, geeks, pawan'] ['geeks', 'for', 'geeks', 'pawan'] ['geeks', 'for, geeks, pawan']
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

