Describe
The partition () method is used to split the string according to the specified delimiter.
If the string contains the specified delimiter, a tuple of $3 is returned, the first one is the substring to the left of the delimiter, the second is the delimiter itself, and the third is the substring to the right of the delimiter.
The partition () method was added in version 2.5.
Grammar
Partition () method syntax:
Str.partition (str)
Parameters
STR: the specified delimiter.
return value
Returns a tuple of $3, the first is the substring to the left of the delimiter, the second is the delimiter itself, and the third is a substring to the right of the delimiter.
Instance
The following example shows the use of the partition () method:
# !/usr/bin/python "http://www.w3cschool.cc/"print str.partition (":// ")
The output is:
('http'://' www.w3cschool.cc/')
Python's partition () method