The split() method in Python is a String method used to split a string into a list of substrings based on a specified delimiter. It takes the delimiter as an argument and returns a list of substrings separated by that delimiter.
Parameter Values
| Parameter | Description |
|---|---|
| sep | The |
| maxsplit | The |
Return Values
The split() method returns a list of strings resulting from the split operation.
How to Use split() in Python
The split() method splits a string into a list using a specified separator. By default, the separator is a space.
text = 'hello world, my name is Alice'
split_text = text.split(', ')
print(split_text)You can also specify the maximum number of splits that the split() method can make.
text = 'apple,banana,cherry,dates'
split_text = text.split(',', 2)
print(split_text)