title: Why can't I initialize a variable to the indices of two other variables working on a string?
body: <p>The wording of my question was not polite to the search feature on the site, so I apologize should someone feel this is a duplicate question, but I must ask anyway.</p>
  
  <p>Working in Python 3.6.1, my goal is to find a substring of letters in a string that are in alphabetical order and if that substring of letters is the longest substring of letters in alphabetical order (aa would be considered alphabetical order), then print out the string. I have not gotten entirely close to the solution but I'm making progress; however, this came up and I'm confounded by it being completely new to Python. My question is, why is this valid:</p>
  
  <pre><code>s = 'hijkkpdgijklmnopqqrs'
  n = len(s)
  i = 0
  a = 0
  for i in range(n-2):
      if s[i] &lt;= s[i+1]:
         a = s[i+1]
         i = s[i+2]
         a = i + a
  print(a)
  </code></pre>
  
  <p>And yet this is not:</p>
  
  <pre><code>s = 'hijkkpdgijklmnopqqrs'
  n = len(s)
  i = 0
  a = 0
  b = ''
  for i in range(n-2):
      if s[i] &lt;= s[i+1]:
         b = a + i
         a = s[i+1]
         i = s[i+2]
         a = a + i
  print(b)
  </code></pre>
  
  <p>When the latter code is run, I receive the error:</p>
  
  <pre class="lang-none prettyprint-override"><code>Traceback (most recent call last):
  File "C:\Users\spect\Desktop\newjackcity.py", line 14, in &lt;module&gt;
  b = a + i
  TypeError: must be str, not int
  </code></pre>
  
  <p>What I am ultimately trying to do is to 'index in' to the string <code>s</code>, compare the zeroth element to the zeroth+1 element and if <code>s[I] &lt; s[I+1]</code>, I want to concatenate the two into my variable <code>a</code> for later printing. Because when I do this, <code>a</code> only prints out two letters in the string. I thought, well initialize the variable first so that <code>a</code> and <code>i</code> can be incremented, then added into <code>a</code> for comparison purposes, and <code>b</code> for printing.</p>
  
  <p>I see now that I'm only going through <code>n-2</code> iterations (in order to compare the second to last letter to <code>n-1</code> so the logic is flawed, but I still don't understand the error of why all of a sudden binding <code>a+i</code> to a variable <code>b</code> will produce a str/int error? In my view saying <code>s[i]</code>; etc. is pulling out the elements as a string and this to me is proven in the fact if I run the first set of code, I get the output:</p>
  
  <pre class="lang-none prettyprint-override"><code>sr
  &gt;&gt;&gt;
  </code></pre>