Python str.split and rsplit: Splitting strings with maxsplit

Python str.split and rsplit: Splitting strings with maxsplit

Break a Python string into a list of strings with str.split:

s = 'ab cd ef'
s.split()  # ['ab', 'cd', 'ef']

Limit splits with maxsplit:

s.split(maxsplit=1)  # ['ab', 'cd ef']

Or split from the right, with a limit:

s.rsplit(maxsplit=1) # ['ab cd', 'ef']