Python String rpartition() Method

Searches the source string from the right for the first match of the specified substring and returns a tuple with everything to the left of the match (from the right), the match, and everything to the right of the first match (again, from the right.)

Syntax

Python
string.partition(value)

Parameters

ParameterDescription
value Required. The string to search for

Example

Python
str = 'You say tomato, I say tomato, the French say tomate.'
print(str.rpartition('tomato'))

Output

('You say tomato, I say ', 'tomato', ', the French say tomate.')