Str.index will return the lowest index in a string where substring sub is found and raise values error if substring not found in given string.
Syntax of Str.index:
index(sub, start, end)
sub=an element or object which index is to be determined.
start=starting index (must be an integer)
end=ending index(must be an integer)
a=’weather’
a.index(‘er’)
Output:5
er is present at 5 position in given string. It returns lowest index of object.
The Syntax of Str.rindex is same but it will return highest index in string where substring found as shown below
[…] Str.index: It will returns the lowest index of string where substring is found in […]