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 Program to Merge Mails
Python Program to Shuffle Deck of Cards
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python Program to Split a List Into Evenly Sized Chunks
Statistical Methods for Machine Learning - Disconver how to Transform data into Knowledge with Pytho...
Python Program to Illustrate Different Set Operations
Python Program to Generate a Random Number
Python timestamp to datetime and vice-versa
Python for Loop
Python Program to Find Sum of Natural Numbers Using Recursion
Python Program to Make a Simple Calculator
Python String partition()
Python String strip()
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python int()
Python Program to Get the Last Element of the List
Python Deep Learning Cookbook - Indra den Bakker
Python String split()
Python Program to Find the Size (Resolution) of a Image
Node.js vs Python for Backend Development
Python Operators
Java InputStream to String
Python Dictionary setdefault()
Python Program to Print Colored Text to the Terminal
Python String lower()
Python List append()
Python String casefold()
Python Program to Find All File with .txt Extension Present Inside a Directory
Python String rsplit()
Python Data Structures and Algorithms - Benjamin Baka
Python range()
Python abs()