Str.partition and str.rpartition separate the string with separator available in string otherwise it will return tuple with string element and two empty string .

Syntax of Str.partition:

a.partition(-)

Output: tuple (head,sep,tail)

head=> the part before the seprator( hello in this case as shown in image)

sep=> the seprator(-) in this case.

tail=>The part after the separator(world in this case as shown in image)

how to write str.partition in python
Str.partition

The difference between str.opartition & str.rpartition is that str.partition function start from the beginning of the string whereas str.rpartition will search from the end of the string. As shown in below image

how to write str.rpartition in python
Str.rpartition

 

By SC

One thought on “Str.partition & rpartition”

Leave a Reply

Your email address will not be published. Required fields are marked *