Table of Contents
The rpartition() splits the string at the last occurrence of the argument string and returns a tuple containing the part the before separator, argument string and the part after the separator.
The syntax of rpartition()
is:
string.rpartition(separator)
1. rpartition() Parameters()
rpartition()
method takes a string parameter separator that separates the string at the last occurrence of it.
2. Return Value from rpartition()
rpartition()
method returns a 3-tuple containing:
- the part before the separator, separator parameter, and the part after the separator if the separator parameter is found in the string
- two empty strings, followed by the string itself if the separator parameter is not found
3. Example: How rpartition() works?
string = "Python is fun" # 'is' separator is found print(string.rpartition('is ')) # 'not' separator is not found print(string.rpartition('not ')) string = "Python is fun, isn't it" # splits at last occurence of 'is' print(string.rpartition('is'))
Output
('Python ', 'is ', 'fun') ('', '', 'Python is fun') ('Python is fun, ', 'is', "n't it")
Related posts:
Python getattr()
Python ord()
Python classmethod()
Converting a Stack Trace to a String in Java
Python Program to Sort a Dictionary by Value
Python Matrices and NumPy Arrays
Python Program to Display Calendar
Python complex()
Python String join()
Python *args and **kwargs
Python Deep Learning - Valentino Zocca & Gianmario Spacagna & Daniel Slater & Peter Roelants
Java InputStream to String
Deep Learning in Python - LazyProgrammer
Python String partition()
Python bytes()
Python Program to Swap Two Variables
Java – String to Reader
Python Dictionary popitem()
Python exec()
Python String isdigit()
Python iter()
Node.js vs Python for Backend Development
Python String maketrans()
Python Program to Find the Square Root
Python String swapcase()
Python int()
Python Tuple count()
Python Program to Display Powers of 2 Using Anonymous Function
Python type()
Python Program to Compute all the Permutation of the String
Python Program to Get Line Count of a File
Python String rjust()