In Python why do some people include len(s)-2 in some cases for finding a word in a string?
<p>Consider:</p>

<pre><code>s = input("Enter a string")
n=0
for count in range(len(s)):
  if s[count:count+3] == "bob":
   n = n+1
print("Number of times bob occurs is: " ,n)
</code></pre>

<p>Why do some people use <code>range(len(s)-2)</code> in their code instead of <code>range(len(s))</code> although both give the right output?</p>

<p>I just don't understand the <code>len(s)-2</code> part.</p>

<p>The last two <code>count</code> values in the for loop, <code>count = len(s)-2</code> and <code>len(s)-1</code> lead to substrings with only 2 or 1 characters, which cannot be equal to a 3 character string.</p>

python string