Python String rindex() Method Last Updated : 07 Jan, 2025 Comments Improve Suggest changes Like Article Like Report Python String rindex() method returns the highest index of the substring inside the string if the substring is found. Otherwise, it raises ValueError.Let's understand with the help of an example: Python s = 'geeks for geeks' res= s.rindex('geeks') print(res) Output10 Note: If start and end indexes are not provided then by default Python String rindex() Method takes 0 and length-1 as starting and ending indexes where ending indexes is not included in our search.Table of ContentSyntax of rindex() rindex() with start or end indexrindex() without start and end indexErrors and ExceptionsSyntax of rindex() string.rindex(value, start, end)Parameters:value : Part that we are searching for.start (optional): Index where the search begins (default is 0).end (optional): Index where the search ends (default is the string’s length).Return: It returns the highest index of the substring inside the string if substring is found. Otherwise it raises an exception.rindex() with start or end indexIf we provide the start and end value to check inside a string, Python String rindex() will search only inside that range. Example: Python a= "ring ring" # checks for the substring in the range 0-4 of the string print(a.rindex("ring", 0, 4)) # same as using 0 & 4 as start, end value print(a.rindex("ring", 0, -5)) b = "101001010" # since there are no '101' substring after string[0:3] # thus it will take the last occurrence of '101' print(b.rindex('101', 2)) Output0 0 5 rindex() without start and end indexIf we don't provide the start and end value to check inside a string, Python String rindex() will search the entire string . Example: Python a = "ring ring" # search for the substring, # from right in the whole string print(a.rindex("ring")) b = "geeks" # this will return the right-most 'e' print(b.rindex('e')) Output: 52Errors and ExceptionsValueError is raised when the substring is not found within the specified range or the entire string.Example: Python s = 'geeks for geeks' res = s.rindex('pawan') print(res) Exception:Traceback (most recent call last): File "/home/dadc555d90806cae90a29998ea5d6266.py", line 6, in res= s.rindex('pawan')ValueError: substring not found Comment More infoAdvertise with us Next Article Python String rindex() Method pawan_asipu Follow Improve Article Tags : Misc Python python-string Practice Tags : Miscpython Similar Reads 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 Python String lstrip() Method The lstrip() method removes leading whitespace characters from a string. We can also specify custom characters to remove from the beginning/starting of the string.Let's take an example to remove whitespace from the starting of a string.Pythons = " Hello Python!" res = s.lstrip() print(res)OutputHell 2 min read Like