The rpartition method
The rpartition method returns a tuple of a string split by the last match of a substring and the specified delimiter parameter.
Syntax
string.rpartition(separator)
Example
Let's apply the rpartition method to the following line:
txt = 'abc_dea'
print(txt.rpartition('_'))
Result of code execution:
('abc', '_', 'dea')
Example
Now let's add an extra character '_' to our string and apply the rpartition method again:
txt = 'ab_cd_ea'
print(txt.rpartition('_'))
As can be seen from the obtained result, the method split the string only by the last match of the character '_':
('ab_cd', '_', 'ea')