rpartition() method of str() class

rpartition() splits the string at the highest index where the substring is found and returns a tuple containing the first part, separator and the second part.

Str Updated 13 Mar 2017 1 min read

Method Name

rpartition

Method Signature

rpartition(separatorSubstring)

Method Overview

  • The rpartition() method of Python str class splits a string into two strings based on a given separator substring.

  • It splits the string at the highest index where the separator substring is found.

  • repartition() returns a tuple containing first part of the string before the separator, separator substring and the second part of the string after the separator.

Example

python
timeFormat      = "HH:MM:SS"

partitionRes    =  timeFormat.rpartition(":")

#print the resulting tuple

print("RPartition Result:")

print(partitionRes)

# print the seconds part

print("SecondsPart:{}".format(partitionRes[2]))

##

Output

Output
RPartition Result:

('HH:MM', ':', 'SS')

SecondsPart:SS