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()
Python Program to Make a Flattened List from Nested List
Python Program to Check Armstrong Number
Python Program to Find Factorial of Number Using Recursion
Python complex()
Python String rjust()
Python Dictionary
Python time Module
Python String count()
Deep Learning with Python - Francois Cholletf
Python while Loop
Python Dictionary update()
Python List reverse()
Python sum()
Convert String to Byte Array and Reverse in Java
Converting a Stack Trace to a String in Java
Python Program to Convert Celsius To Fahrenheit
Python Program to Find the Largest Among Three Numbers
Python String casefold()
Python reversed()
Python Program to Print Output Without a Newline
Python float()
Intelligent Projects Using Python - Santanu Pattanayak
Python Dictionary get()
String Hashing
Python list()
Python Program to Display Calendar
Count Occurrences of a Char in a String
Python Program to Check Whether a String is Palindrome or Not
Python List sort()
Python next()
Python Program to Extract Extension From the File Name