Home >>Python String Methods >Python String rpartition() Method

Python String rpartition() Method

Python String rpartition() Method

Python String rpartition() Method in python splits the string from the index of parameter of a specified string and returns the tuple. The tuple splits the string into three parts before the separator, argument of the string and the part after the separator. If the separator not found, it returns the empty tuple.

Syntax:
string.rpartition(value)

Parameter Values

Parameter Description
value It is Required to search the string
Here is an Example of Python String rpartition() Method:

txt = "blue color is my lucky color, blue color are my favorite color"
p = txt.rpartition("blue")
print(p)

Output:
('blue color is my lucky color, ', 'blue', ' color are my favorite color')
Example 2:

rpart = "javaScript is a scripting language"   
rpart2 = rpart.rpartition("is")   
print(rpart2)  
rpart2 = rpart.rpartition("javaScript")  
print(rpart2)  
rpart2 = rpart.rpartition("language")  
print(rpart2)    
rpart2 = rpart.rpartition("va")  
print(rpart2)  

Output:
('javascript ', 'is', ' a scripting language')
('', 'javascript', ' is a scripting language')
('javascript is a scripting ', 'language', '')
('ja', 'va', 'script is a scripting language')