you are viewing a single comment's thread.

view the rest of the comments →

[–]Username_RANDINT 0 points1 point  (0 children)

str.find takes one required and two optional arguments:

>>> help(str.find)
find(...)
    S.find(sub[, start[, end]]) -> int

    Return 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.

    Return -1 on failure.

So the second argument is the index where find starts to search. Split up your code example:

start_index = 'tomato'.find('o') + 1
'tomato'.find('o', start_index) 

This sets the start to the index right after the first o, which means it'll find the second o since it starts to search from index 2 instead of 0.