Home >>Python String Methods >Python String partition() Method

Python String partition() Method

Python String partition() Method

Python string partition() method is used to look for a specified string and splits that string into a tuple containing three elements. the first element contains the part before the required string, the second element contains the required string and therefore the third element contains the part after the string.

Syntax:
string.partition(value)

Parameter Values

Parameter Description
value This is a required parameter. It defines the string to search for.
Here is an example of Python partition() method:

txt = "Hi!! My name id Jerry and i'm a developer"
x = txt.partition("Jerry")
print(x)

Output:
('Hi!! My name id ', 'Jerry', " and i'm a developer")
Example 2:

txt = "Hi!! My name id Jerry and i'm a developer"
x = txt.partition("Abhi")
print(x)

Output:
("Hi!! My name id Jerry and i'm a developer", '', '')

No Sidebar ads