Function Details: partition

Description

Partition the string into three parts using the given separator.

Extended Description

partition is a Python string method that splits string into 3-part tuple (before_separator, separator, after_separator) based on first occurrence of separator. Belongs to string division family with split and rpartition. Unlike split, always returns three elements, making it ideal for structured parsing. Works with strip for clean text processing. If separator not found, returns original string and two empty strings. Essential for stable parsing where separator position and surrounding content are important. Common in parsing key-value pairs and structured text processing.


Read More about partition from Python Documentation

Function Signature



Module: builtins

Class: str

Parameters



Parameter List


  • sep: str

Return


Returns a tuple of three strings: (part_before_separator, separator, part_after_separator)


Return Type


Tuple[str, str, str]

Output

Explanation

This example demonstrates the basic usage of partition(). It splits the string at the first occurrence of '-'.