split() method returns 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 there is no limit.
Returns : Returns a list of strings after breaking the given string by the specified separator.
CODE 1
text = 'geeks for geeks' # Splits at space print(text.split()) word = 'geeks, for, geeks' # Splits at ',' print(word.split(',')) word = 'geeks:for:geeks' # Splitting at ':' print(word.split(':')) word = 'CatBatSatFatOr' # Splitting at 3 print([word[i:i+3] for i in range(0, len(word), 3)]) |
Output :
['geeks', 'for', 'geeks'] ['geeks', 'for', 'geeks'] ['geeks', 'for', 'geeks'] ['Cat', 'Bat', 'Sat', 'Fat', 'Or']
CODE 2
word = 'geeks, for, geeks, pawan' # maxsplit: 0 print(word.split(', ', 0)) # maxsplit: 4 print(word.split(', ', 4)) # maxsplit: 1 print(word.split(', ', 1)) |
Output :
['geeks, for, geeks, pawan'] ['geeks', 'for', 'geeks', 'pawan'] ['geeks', 'for, geeks, pawan']
Recommended Posts:
- Python | Exceptional Split in String
- Python | K Character Split String
- How to split a string in C/C++, Python and Java?
- Python | Split flatten String List
- Python | String Split including spaces
- Python | Split multiple characters from string
- Python | Split given string into equal halves
- Python - Split String of list on K character
- Python | Split string into list of characters
- Python program to split and join a string
- Python | Split string on Kth Occurrence of Character
- Python | Split strings and digits from string list
- Python | Split string in groups of n consecutive characters
- Split a string in equal parts (grouper in Python)
- Python | Rear stray character String split
- Python | Split CamelCase string to individual strings
- Python | Pandas Split strings into two List/Columns using str.split()
- Python | Ways to split a string in different ways
- numpy string operations | split() function
- Split a String into columns using regex in pandas DataFrame
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : agarwalmayur08

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.
