find() String Method in Python with Examples
Syntax: find() String Method
S.find(sub, start, end) -> int
In above syntax -> int
indicates this method finally returns an integer value.
find() Syntax Explanation
find()
method returns the lowest index in S
where substring sub
is found,
such that sub
is contained within S[start:end]
. Optional
arguments start
and end
are interpreted as in slice notation.
And, if substring sub
is not found in string it returns -1
.
Example: find() String Method
message = 'Welcome to Python withot TAB!'
print(message.find('come'))
print(message.find('Come'))
Output
3 -1
Related String Methods