Python str.split() Method
The split() method splits a string into a list.
You can specify the separator, default separator is any whitespace. When the maxsplit argument is returned, the list will contain the specified number of elements plus one.
Syntax
string.split(separator, maxsplit)
Parameters
| Parameter | Description |
|---|---|
separator |
Optional. Specifies the separator to use when splitting the string. Default is whitespace |
maxsplit |
Optional. Specifies how many splits to do. Default value is -1 (all occurrences) |
Return Value
A list of strings.
Example
Using the split() method:
Output
Click Run to execute your code
Enjoying these tutorials?