Python String rfind() Method Last Updated : 21 Feb, 2025 Comments Improve Suggest changes Like Article Like Report Python String rfind() method returns the rightmost index of the substring if found in the given string. If not found then it returns -1.Example Python s = "GeeksForGeeks" print(s.rfind("Geeks")) Output8 Explanationstring "GeeksForGeeks" contains the substring "Geeks" twice.rfind() method starts the search from the right side of the string, so it finds the last occurrence of "Geeks", which starts at index 8 (the second occurrence).Syntax of rfind() methodstr.rfind(sub, start, end)Parameterssub: It’s the substring that needs to be searched in the given string. start: Starting position where the sub needs to be checked within the string. end: Ending position where suffix needs to be checked within the string. Return TypeReturns the right-most index of the substring if it is found in the given string; if not found, then it returns -1.Note: If start and end indexes are not provided then, by default it takes 0 and length-1 as starting and ending indexes where ending indexes are not included in our search.Examples of rfind() Method1. Basic usages of Python String find() Method Python word = 'geeks for geeks' # Returns highest index of the substring res = word.rfind('geeks') print (res ) res = word.rfind('for') print (res ) word = 'CatBatSatMatGate' # Returns highest index of the substring res = word.rfind('ate') print(res) Output10 6 13 ExplanationExample 1: rfind('geeks') in 'geeks for geeks' returns 12 (last occurrence of 'geeks').Example 2: rfind('for') in 'geeks for geeks' returns 5 (last occurrence of 'for').Example 3: rfind('ate') in 'CatBatSatMatGate' returns 12 (last occurrence of 'ate').2. Using Python String rfind() Method with given start and end position inside StringIf we pass the start and end parameters to the Python String rfind() Method, it will search for the substring in the portion of the String from its right side. Python word = 'geeks for geeks' # Substring is searched in 'eeks for geeks' print(word.rfind('ge', 2)) # Substring is searched in 'eeks for geeks' print(word.rfind('geeks', 2)) # Substring is searched in 'eeks for geeks' print(word.rfind('geeks ', 2)) # Substring is searched in 's for g' print(word.rfind('for ', 4, 11)) # finding substring using -ve indexing print(word.rfind('geeks', -5)) Output10 10 -1 6 10 ExplanationExample 1: rfind('ge', 2) returns 2, as it finds 'ge' starting from index 2.Example 2: rfind('geeks', 2) returns 0, finding 'geeks' from index 2.Example 3: rfind('geeks ', 2) returns -1, as it doesn’t find 'geeks ' from index 2.Example 4: rfind('for ', 4, 11) returns 6, finding 'for ' within the range 4-11.Example 5: rfind('geeks', -5) returns 7, finding 'geeks' from index -5.3. Practical ApplicationHere, we check one email address and the Top Level Domain (TLD) matching our necessary condition. Then we print, "Email matched" else "Email not matched", followed by the TLD String. Even if this email address contains a ".com" substring, rfind() helped to extract the TLD string more efficiently. Python email = '[email protected]' last_dot_pos = email.rfind('.', 1) tld_string = email[last_dot_pos:] if tld_string == ".com": print("Email matched") else: print("Email not matched, tld:", tld_string) OutputEmail not matched, tld: .xyz Explanationrfind('.', 1) searches for the last occurrence of '.' in the string starting from index 1.It finds the last dot '.' at position 10 in '[email protected]'.email[last_dot_pos:] extracts the TLD (Top-Level Domain) starting from the last dot: '.com'.The code checks if the extracted TLD matches ".com".If it matches, "Email matched" is printed; otherwise, it prints the TLD. Comment More infoAdvertise with us Next Article Python String rfind() Method pawan_asipu Follow Improve Article Tags : Misc Python Python-Built-in-functions python-string Practice Tags : Miscpython Similar Reads Python String isdigit() Method The isdigit() method is a built-in Python function that checks if all characters in a string are digits. This method returns True if each character in the string is a numeric digit (0-9) and False otherwise. Example:Pythona = "12345" print(a.isdigit()) b = "1234a5" print(b.isdigit())OutputTrue False 3 min read Python String isidentifier() Method The isidentifier() method in Python is used to check whether a given string qualifies as a valid identifier according to the Python language rules. Identifiers are names used to identify variables, functions, classes, and other objects. A valid identifier must begin with a letter (A-Z or a-z) or an 3 min read Python String islower() Method The islower() method in Python checks if all characters in a string are lowercase. It returns True if all alphabetic characters are lowercase, otherwise, it returns False, if there is at least one uppercase letter.Let's look at a quick example of using the islower() method.Pythons = "hello" res = s. 2 min read Python String isnumeric() Method The isnumeric() method is a built-in method in Python that belongs to the string class. It is used to determine whether the string consists of numeric characters or not. It returns a Boolean value. If all characters in the string are numeric and it is not empty, it returns âTrueâ If all characters i 3 min read Python String isprintable() Method Python String isprintable() is a built-in method used for string handling. The isprintable() method returns "True" if all characters in the string are printable or the string is empty, Otherwise, It returns "False". This function is used to check if the argument contains any printable characters suc 3 min read Python String isspace() Method isspace() method in Python is used to check if all characters in a string are whitespace characters. This includes spaces (' '), tabs (\t), newlines (\n), and other Unicode-defined whitespace characters. This method is particularly helpful when validating input or processing text to ensure that it c 2 min read Python String istitle() Method The istitle() method in Python is used to check whether a string follows the title case formatting. In a title-cased string, the first letter of each word is capitalized, and all other letters in the word are in lowercase. This method is especially useful when working with formatted text such as tit 3 min read Python String isupper() method isupper() method in Python checks if all the alphabetic characters in a string are uppercase. If the string contains at least one alphabetic character and all of them are uppercase, the method returns True. Otherwise, it returns False. Let's understand this with the help of an example:Pythons = "GEE 3 min read Python String join() Method The join() method in Python is used to concatenate the elements of an iterable (such as a list, tuple, or set) into a single string with a specified delimiter placed between each element.Lets take a simple example to join list of string using join() method.Joining a List of StringsIn below example, 3 min read String lower() Method in Python lower() method in Python converts all uppercase letters in a string to their lowercase. This method does not alter non-letter characters (e.g., numbers, punctuation). Let's look at an example of lower() method:Pythons = "HELLO, WORLD!" # Change all uppercase letters to lowercase res = s.lower() prin 3 min read Like