- split
- list
split
- Special case: To split a string to its characters: Use the list() function.
- Split using more than one splitter: use re.split
examples/lists/split.py
words = "ab:cd::ef".split(':') print(words) # ['ab', 'cd', '', 'ef'] by_space = "foo bar baz".split(' ') print(by_space) # ['foo', '', '', 'bar', 'baz'] # special case: split by spaces names = "foo bar baz".split() print(names) # ['foo', 'bar', 'baz'] # special case: split to characters chars = list("ab cd") print(chars) # ['a', 'b', ' ', 'c', 'd']