Python String partition() Method Syntax

Syntax: string.partition(separator)

Parameters: 

  • separator: a substring that separates the string

Return: Returns a tuple of 3 elements. The substring before the separator, the separator, the part after the separator.

Python String partition() Method

Python String partition() method splits the string at the first occurrence of the separator and returns a tuple containing the part before the separator, the separator, and the part after the separator. Here, the separator is a string that is given as the argument.

Example: 

Python3




str = "I love Geeks for geeks"
print(str.partition("for"))


Output: 

('I love Geeks ', 'for', ' geeks')

Similar Reads

Python String partition() Method Syntax

...

String partition() in Python Examples

Syntax: string.partition(separator) Parameters:  separator: a substring that separates the string Return: Returns a tuple of 3 elements. The substring before the separator, the separator, the part after the separator....

Contact Us