Python String partition() MethodLast Updated : 31 Dec 2025 Python partition() method splits the string from the string specified in parameter. It splits the string from at the first occurrence of parameter and returns a tuple. The tuple contains the three parts before the separator, the separator itself, and the part after the separator. It returns an empty tuple having seperator only, if the seperator not found. Syntax of Python String partition() MethodThe method signature is given below. Parameters
ReturnIt returns a tuple, A 3-Tuple. Different Examples for Python String partition() MethodLet's see some examples of partition(sep) method to understand it's functionality. Example 1First, let's see simple use of partition method. Example 2If the separator is not found, It returns a tuple containing string itself and two empty strings. See the example below. Output:
('Python is a programming language', '', '')
Next TopicPython Strings |
We request you to subscribe our newsletter for upcoming updates.