String Methods
str.rpartition()
Split at the last occurrence of a nonempty literal separator. Always return a three-part tuple containing the text before, the separator, and text after. If absent, the original text is the third item and the first two are empty. The original string is unchanged.
Formal Syntax & Structure
python syntaxpython
text.rpartition(sep, /)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| sep | str | Nonempty literal separator. |
Return Value
tuple[str, str, str]
Three-part tuple preserving the separator.
Working Example
Example Snippetpython
print("a:b:c".rpartition(":"))print("abc".rpartition(":"))