CBSE Class 11 Computer Science
Question 6 of 19
Strings in Python — Question 2
Back to all questionsThe split() function breaks up a string at the specified separator and returns a list of substrings. The syntax is str.split([separator, [maxsplit]]). The split() method takes a maximum of 2 parameters:
separator (optional) — The separator is a delimiter. The string splits at the specified separator. If the separator is not specified, any whitespace (space, newline, etc.) string is a separator.
maxsplit (optional) — The maxsplit defines the maximum number of splits. The default value of maxsplit is -1, which means no limit on the number of splits.
For example,
x = "blue;red;green"
print(x.split(";"))['blue', 'red', 'green']