Python rpartition() method
Description
The rpartition() method is similar to the partition() method, except that this method searches for the separator starting from the end, i.e., the right side, of the target string.
If the string contains the specified separator, a 3-tuple is returned: the first element is the substring to the left of the separator, the second is the separator itself, and the third is the substring to the right of the separator.
Syntax
rpartition() method syntax:
str.rpartition(str)
Parameters
str: the specified separator.
Return Value
Returns a 3-tuple: the first element is the substring to the left of the separator, the second is the separator itself, and the third is the substring to the right.
Example
The following example shows how to use the rpartition() method:
Example (Python 2.0+)
#!/usr/bin/python
str
=
"
www.runoob.com
"
str
.
rpartition
(
"
.
"
)
The output is:
('www.runoob', '.', 'com')
Python Strings