Use str.find when a string search should return the substring’s position without raising an exception when no match exists. It returns the lowest matching index or -1 when the substring is absent. section 4.3.3
Keep these usage rules in mind:
- Call find on strings only; other sequence types do not provide this method. section 4.3.3
- Check whether the returned index is greater than or equal to zero before using the match position. section 4.3.3
- Prefer find or rfind for substring searches when avoiding the ValueError raised by index matters. section 4.3.3
Filtering task content
A task loader can search the title, description, and completion note for requested content. If no field contains a match, it skips the current row with continue; find avoids an exception during that test. section 14.2.3
def find_string(substr):
str_index = the_str.find(substr)
if str_index >= 0:
# do something with the str_index
else:
# do something when the substr isn’t present
Use the returned index to separate the match-found path from the substring-absent path. section 4.3.3

