split() string method in Python

The split string method splits the string into a list using a delimiter.

Syntax string.split(separator, maxsplit)

• Separator: We can specify the separator; default separator is any whitespace.

Example: Split a string into a list where each word is a list item.

Python

text = "apple,banana,cherry"
print(text.split(","))   
# Output: ['apple', 'banana', 'cherry']