ReferenceString methods
str.split()
Breaks a string into a list of pieces.
Signature
text.split(sep=None, maxsplit=-1)Parameters
| Name | Means |
|---|---|
sep | what to split on; any whitespace when omitted |
maxsplit | how many splits to make at most |
Returns
A list of strings.
Example
Python
print("a,b,c".split(","))
print(" a b ".split())
print(" a b ".split(" "))
print("a,b,c".split(",", 1))Output
['a', 'b', 'c'] ['a', 'b'] ['', '', 'a', '', '', 'b', ''] ['a', 'b,c']