Rpartition() method of str() class

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:

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:

RPartition Result:

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

SecondsPart:SS


Copyright 2024 © pythontic.com