In python3
,
That means string_a[i:i + k] == string_b[j:j + k]
is comparing two new sliced sequence by comparing elements in them, while not creating new string but new sequence.
does Python optimize this?
It is hard to say it inefficient or not without any of you code.
Is it possible that using a for loop and comparing character by character could be more efficient?
No.