TheDeveloperBlog.com

Home | Contact Us

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

Python String | rfind() method with Examples

Python String rfind() 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 rfind() Method

Python rfind() method finds a substring in in the string and returns the highest index. It means it returns the index of most righmost matched subtring of the string. It returns -1 if substring not found.

Signature

rfind(sub[, start[, end]])

Parameters

sub : substring to be searched.

start (optional) : starting index to start searching.

end (optional) : end index where to search stopped.

Return

It returns either index of substring or -1.

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

Python String rfind() Method Example 1

Let's have a simple example to implement the rfind() method. It returns highest index of the substring.

# Python rfind() method example
# Variable declaration
str = "Learn Java from TheDeveloperBlog"
# calling function
str2 = str.rfind("Java")
# displaying result
print(str2)

Output:

16

Python String rfind() Method Example 2

One more example to understand the working of rfind() method.

# Python rfind() method example
# Variable declaration
str = "It is technical tutorial"
# calling function
str2 = str.rfind("t")
# displaying result
print(str2)

Output:

18

Python String rfind() Method Example 3

This method takes other three parameters including two optional. Let's provide start and end index to the method.

# Python rfind() method example
# Variable declaration
str = "It is technical tutorial"
# calling function
str2 = str.rfind("t",5) # Only starting index is passed
# displaying result
print(str2)
str2 = str.rfind("t",5,10) # Start and End both indexes are passed
print(str2)

Output:

18
6

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