title: Python - Why do the find and index methods work differently?
body: <p>In Python, <code>find</code> and <code>index</code> are very similar methods, used to look up values in a sequence type. <code>find</code> is used for strings, while <code>index</code> is for lists and tuples. They both return the lowest index (the index furthest to the left) that the supplied argument is found.</p>
  
  <p>For example, both of the following would return <code>1</code>:</p>
  
  <pre><code>"abc".find("b")
  [1,2,3].index(2)
  </code></pre>
  
  <p>However, one thing I'm somewhat confused about is that, even though the two methods are very similar, and fill nearly the same role, just for different data types, they have very different reactions to attempting to find something not in the sequence.</p>
  
  <pre><code>"abc".find("d")
  </code></pre>
  
  <p>Returns <code>-1</code>, to signify 'not found', while</p>
  
  <pre><code>[1,2,3].index(4)
  </code></pre>
  
  <p>raises an exception.</p>
  
  <p>Basically, why do they have different behaviors? Is there a particular reason, or is it just a weird inconsistency for no particular reason?</p>
  
  <p>Now, I'm not asking how to deal with this &ndash; obviously, a <code>try</code>/<code>except</code> block, or a conditional <code>in</code> statement, would work. I'm simply asking what the rationale was for making the behavior in just that particular case different. To me, it would make more sense to have a particular behavior to say not found, for consistency's sake.</p>
  
  <p>Also, I'm not asking for opinions on whether the reason is a good reason or not &ndash; I'm simply curious about what the reason <em>is</em>.</p>
  
  <p><strong>Edit:</strong> Some have pointed out that strings also have an <code>index</code> method, which works like the <code>index</code> method for lists, which I'll admit I didn't know, but that just makes me wonder why, if strings have both, lists only have <code>index</code>.</p>