Function Details: rpartition

Description

Partition the string into three parts using the given separator.

Extended Description

rpartition is a Python string method that splits string into 3-part tuple (before_separator, separator, after_separator) based on last occurrence of separator. Belongs to string division family with split and partition. Like partition, always returns three elements but searches from right side. Works with strip for clean text processing. If separator not found, returns two empty strings and original string. Essential for parsing from right side where separator position matters. Common in file path processing, URL parsing, and handling nested structures.


Exceptions


  • ValueError: If the separator is an empty string

Read More about rpartition from Python Documentation

Function Signature



Module: builtins

Class: str

Parameters



Parameter List


  • sep: str

Return


Returns a tuple of three strings: (head, separator, tail)


Return Type


Tuple[str, str, str]

Output

Explanation

Basic usage of rpartition() to split the string at the last comma.