Describe
The Python Rsplit () method splits a string by specifying a delimiter and returns a list with the default delimiter of all null characters, including spaces, line breaks (\ n), tabs (\ t), and so on. Similar to the split () method, except that the split begins at the end of the string.
Grammar
Rsplit () method syntax:
S.rsplit ([Sep=none][,count=s.count (Sep)])
Parameters
- Sep--optional parameter, specified delimiter, default to all null characters, including spaces, newline (\ n), tab (\ t), and so on.
- Count--optional parameter, number of splits, default to the total number of occurrences of the delimiter in the string.
return value
Returns the segmented list of strings.
Instance
The following example shows how the Rsplit () method is used:
#!/usr/bin/python3s = "This is string EXAMPLE....WOW!!!" Print (S.rsplit ()) Print (S.rsplit (' I ', 1)) Print (S.rsplit (' W '))
The result of the above example output is as follows:
[' This ', ' is ', ' string ', ' EXAMPLE....WOW!!! '] [' This is str ', ' ng example....wow!!! '] [' This is string example .... ', ' o ', '!!! ']
Python Rsplit () method