split()
Splits a string into pieces and makes a list.
Syntax
text.split(separator)
Description
Splits the string at the given separator and returns the pieces as a list. If no separator is given, it splits at whitespace.
Returns
A list made of the pieces.
Example
Loading editor…
Expected output
['apple', 'pear', 'cherry'] ['one', 'two', 'three']
When to use?
Separating a CSV row into fields, splitting a sentence into words.