tl; dr: String calls indexhave a lot of optimizations under the hood and you don't have to do rich comparisons. And list, and tuplemust fulfill them; volatility does not matter.
stringobject.c, , index string_find_internal, stringlib_find_slice, stringlib_find, fastsearch.
fastsearch , , . , Boyer-Moore python. 1- , fastsearch :
} else if (mode == FAST_SEARCH) {
for (i = 0; i < n; i++)
if (s[i] == p[0])
return i;
}
, C.
, . tuple list s?
; , :
for (i = start; i < stop && i < Py_SIZE(self); i++) {
int cmp = PyObject_RichCompareBool(self->ob_item[i], v, Py_EQ);
if (cmp > 0)
return PyInt_FromSsize_t(i);
, ==, PyObject_RichCompareBool . ( object.c, ), , , , , , NotImplemented singleton , , .
, , index, . .