Important Notice:

Course Content
The Calendar Module
Library Function/Predefined Functions
0/4
Sys Module
Library Function/Predefined Functions
0/2
OS Module
Library Function/Predefined Functions
0/2
Functions in Python (Chapter-10) M3-R5
About Lesson

partition( ):-  

              The partition() method searches for a specified string, and splits the string into a tuple containing three elements. The first element contains the part before the specified string. The second element contains the specified string. The third element contains the part after the string.

Syntax:-       string.partition(value)

txt = “I could eat bananas all day”

x = txt.partition(“bananas”)

print(x)

Output

(‘I could eat ‘, ‘bananas’, ‘ all day’)

Note:- If the specified value is not found, the partition() method returns a tuple containing: 1 – the whole string, 2 – an empty string, 3 – an empty string:

txt = “I could eat bananas all day”

x = txt.partition(“apples”)

print(x)

Output

(‘I could eat bananas all day’, ”, ”)

 

error: Content is protected !!