This has always been annoying ;-) Contrary to one answer, there's nothing special about -1 with respect to strings; e.g.,
>>> "abc"[-1]
'c'
>>> [2, 3, 42][-1]
42
The problem with find()
in practice is that -1 is in fact not special as an index. So code using find()
is prone to surprises when the thing being searched for is not found - it was noted even before Python 1.0.0 was released that such code often went on to do a wrong thing.
No such surprises occur when index()
is used instead - an exception can't be ignored silently. But setting up try/except
for such a simple operation is not only annoying, it adds major overhead (extra time) for what "should be" a fast operation. Because of that, string.find()
was added in Python 0.9.9 (before then, only string.index()
could be used).
So we have both, and that persists even into Python 3. Pick your poison :-)