Python‎ > ‎str‎ > ‎

str.partition()

 
Definition
In Python, string can be partitioned with the function str.partition(). In order to do that partition() has defined where to partition.

Syntax
str.partition(x)

Parameters
x=string

Examples
The examples are:
 >>> "Python".partition("hon")
('Pyt', 'hon', '')
>>> 
>>> "Python Lake".partition("Lake")
('Python ', 'Lake', '')
>>> "Python Lake".partition("ke")
('Python La', 'ke', '')
>>> 

str.partition==tuple
The str.partition converted the string into tuple.
 >>> "Python Lake".partition("Lake")
('Python ', 'Lake', '')
>>> type("Python Lake".partition("Lake"))
<class 'tuple'>
>>> z="Python Lake".partition("Lake")
>>> z.count("Lake")
1

len(str.partition())
The method return with length of partition string.
 >>> len("Python Lake".partition("Lake"))
3

Comments