First page Back Continue Last page Overview Graphics

More on split

If sep is given, consecutive delimiters are not grouped together and are deemed to delimit empty strings (e,g, '1,,2'.split(',') returns ['1', '', '2']).

>>> doc = "/usr/share/doc/python//html"

>>> doc.split("/")

['', 'usr', 'share', 'doc', 'python', '', 'html']

The sep argument may consist of multiple characters (e.g., '1<>2<>3'.split('<>') returns ['1', '2', '3']).

Splitting an empty string with a specified separator returns [''].

If sep is not specified or None, every run of consecutive whitespaces ia regarded as a single separator, and the result will contain no empty strings at the start or end if the string has leading or trailing whitespace.

>>> mammon = "The god of the world's"

>>> mammon.rsplit()

['The', 'god', 'of', 'the', "world's"]

>>> mammon.rsplit(" ")

['The', '', '', 'god', '', '', 'of', 'the', "world's"]