String Methods
str.partition()
Split at the first 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 first item and the last two are empty. The original string is unchanged.
Formal Syntax & Structure
python syntaxpython
text.partition(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".partition(":"))print("abc".partition(":"))