.split(), .splitlines(), .rsplit().split() - if no parameter is given, the string is split on each space.
- if a parameter is given, for example ",", the string will be split in to a list on each comma
.splitlines() - will split a string into a list based on the EOL "\n" character
.rsplit() .split(), .splitlines(), .rsplit() Syntaxlist_variable = string_variable.split(sep)
sep is an optional parameter, if a character is given, the string_variable will be split on that character .split(), .splitlines(), .rsplit() Examplesdata before : This is a file with many words and many lines
data = data.split()
data after ['This', 'is', 'a', 'file', 'with', 'many', 'words', 'and', 'many', 'lines'] Notice: the data started as a string and was converted into a list
|
|