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 Check If a List is Empty
Java String to InputStream
Python setattr()
Python String istitle()
Python Program to Safely Create a Nested Directory
Python Program to Swap Two Variables
Python Matrices and NumPy Arrays
Python while Loop
Python Program to Find Armstrong Number in an Interval
Python reversed()
Python locals()
Python Program to Make a Simple Calculator
Python Program to Display Powers of 2 Using Anonymous Function
Python del Statement
Python Program to Find Sum of Natural Numbers Using Recursion
Python String ljust()
Python Program to Check Whether a String is Palindrome or Not
Python Dictionary pop()
Python Strings
Python Machine Learning - Sebastian Raschka
Python Program to Find ASCII Value of Character
Convert String to int or Integer in Java
Python Program to Get File Creation and Modification Date
Python Machine Learning Third Edition - Sebastian Raschka & Vahid Mirjalili
Python sum()
Python Program to Return Multiple Values From a Function
Python Type Conversion and Type Casting
Python Program to Find the Largest Among Three Numbers
Python Keywords and Identifiers
Python print()
Python String rsplit()
Intelligent Projects Using Python - Santanu Pattanayak