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
pythonstring.rpartition(separator)
Example
Let's apply the rpartition method to the following line:
pythontxt = 'abc_dea'
print(txt.rpartition('_'))
Result of code execution:
python('abc', '_', 'dea')
Example
Now let's add an extra character '_' to our string and apply the rpartition method again:
pythontxt = '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 '_':
python('ab_cd', '_', 'ea')