rpartition( ) Function
The partition( ) Function is used to search for a particular substring mentioned in it and creates a tuple that has three values.
The First value is the one that resides on the left side of the search substring.
The second value is the searched substring itself.
And the third value is the one that resides on the right side of the search substring.
x = "Hello Beautiful World" y = x.rpartition("Beautiful") print(y)
In the above code, we have declared a string 'Hello Beautiful World'. And assigned it to a variable 'x'.
Then we have used the 'x.partition("Beautiful")' function to search for the substring "Beautiful" and create a Tuple with three values.
Now if you look at the output, a tuple with three values is formed.
Now, let us say, we have specified a value in the 'partition( )' Function that is not found.
x = "Hello Beautiful World" y = x.rpartition("Wonderful") print(y)
In the above code, we have declared a string 'Hello Beautiful World'. And assigned it to a variable 'x'.
Then we have used the 'x.rpartition("Wonderful")' function to search for the substring "Wonderful" and create a Tuple with three values.
But the substring 'Wonderful' is not present in the String 'Hello Beautiful World'. In such case, the elements of the tuple would be the complete String 'Hello Beautiful World' itself as the last element. And the first and second elements would vacant.
Now if you look at the output, a tuple with three values is formed.