split string in python

Python splits string via str.split() and str.rsplit() as well, the latter of which starts splitting from the end of the string.
This can be useful when using the second parameter, maxsplit.

For example:

>>> "string with multiple spaces".split(" ", maxsplit=1)
['string', 'with multiple spaces']

This parameter can be used e.g. to split command and arguments apart.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.