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 Set issuperset()
Converting String to Stream of chars
Python String partition()
String Hashing
Python object()
Python Dictionary items()
Python Program to Slice Lists
Python Program to Reverse a Number
Python sorted()
Deep Learning with Applications Using Python - Navin Kumar Manaswi
Python @property decorator
Python Multiple Inheritance
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python repr()
Python Inheritance
Python String isalpha()
Python String expandtabs()
Python reversed()
Python strftime()
Python String center()
Python Sets
Python String count()
Python Dictionary fromkeys()
String Processing with Apache Commons Lang 3
Python String lower()
Python super()
Python Program to Add Two Matrices
Python issubclass()
Python Program to Differentiate Between type() and isinstance()
Python String isspace()
Python Dictionary clear()
Introduction to Machine Learning with Python - Andreas C.Muller & Sarah Guido