Python

Python Menu

Python

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

Definition

The rfind() method finds the last occurrence of the specified value. It returns -1 if the value is not found. This method is almost the same as the rindex() method.

Syntax

string.rfind(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 Python scripting language." result = testStr.rfind("Python") print(result) # using the start and end parameters testStr = "Welcome to the Python tutorials." result = testStr.rfind("t", 3 , 9) #finds last occurrence of 't' from positions 5 to 9 print(result)

Introduction

Python Basics

Python Advance

Data Science Python Tutorials

Python Functions and Methods