Python

Python Menu

Python

Python String rindex() - Definition, Syntax, Parameters, Examples

Definition

The rindex() method finds the last occurrence of the specified value. It raises an exception if the value is not found. This method is almost the same as the rfind() method.

Syntax

string.rindex(value, start, end)

Parameters

Parameter Description
value Required. The value to search for
start Optional. Where to start the search. Default is 0
end Optional. Where to end the search. Default is to the end of the string

Examples:

testStr = "Welcome to the Python tutorials. Python is a scripting language." result = testStr.rindex("Python") print(result) # using the start and end parameters testStr = "Welcome to the Python tutorials. Python is a scripting language." result = testStr.rindex("t", 10, 25) print(result) # comparison between rindex() and rfind() testStr = "Welcome to the Python tutorials." print(testStr.rfind("x")) print(testStr.rindex("x"))

Introduction

Python Basics

Python Advance

Data Science Python Tutorials

Python Functions and Methods