Python - String Method - rpartition() Tutorial
This method will split the string into three-part based on the last occurrence of the argument string and return it in the form of a tuple.
The first part will be the string before the last occurrence of the argument, the second part is itself an argument and the third part will be the string after the last occurrence of the argument.
Syntax-
String.rpartition(separator)
#separator - It is a string that will split the original string
into 3 parts based on the last occurrence of the separator.
Example-
str1 = "Sam is good in math, but he is bad in english"
# 'is' separator is found, wil split it at first occurence
print(str1.rpartition('is '))
# 'not' separator is not found
print(str1.rpartition('not '))
Output-
('Sam is good in math, but he ', 'is ', 'bad in english')
('', '', 'Sam is good in math, but he is bad in english')
In the above program, if the argument is not found in the string, then in first and second part it will returned empty string, in third part it will return whole string.