TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Python String rpartition() method with Examples

Python String rpartition() method with Examples on capitalize(), center(), count(), encode(), find(), format(), index(), join(), lower(), ljust(), isupper(), istitle(), isspace(), isprintable(), isnumeric(), islower() etc.

<< Back to PYTHON

Python String rpartition() Method

Python rpartition() method splits the string at the last occurrence of seperator substring.It splits the string from the last occurrence of parameter and returns a tuple. The tuple contains the three parts before the separator, the separator itself, and the part after the separator.

It returns an empty tuple having seperator only, if the seperator not found.

The method signature is given below.

Signature

rpartition(sep)

Parameters

sep: A string parameter which separates the string.

Return

It returns a tuple, A 3-Tuple.

Let's see some examples of rpartition(sep) method to understand it's functionality.

Python String rpartition() Method Example 1

Let's see a simple use of partition method in various scenario.

# Python rpartition() method example
# Variable declaration
str = "Java is a programming language"
# Calling function
str2 = str.rpartition("is")
# Displaying result
print(str2)
# seperator is at begining
str2 = str.rpartition("Java")
print(str2)
# seperator at ent
str2 = str.rpartition("language")
print(str2)
# when seperater is a substring
str2 = str.rpartition("av")
print(str2)

Output:

('Java ', 'is', ' a programming language'')
('', 'Java', ' is a programming language')
('Java is a programming ', 'language', '')
('J', 'av', 'a is a programming language')

Python String partition() Method Example 2

if the separator is not found, It returns a tuple containing string itself and two empty strings to the right. See the example below.

# Python rpartition() method example
# Variable declaration
str = "Java is a programming language"
# Calling function
str2 = str.rpartition("not")
# Displaying result
print(str2)

Output:

('', '', 'Java is a programming language')

Next TopicPython Strings




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf