title: Standard python classes that support math operators?
body: <p>Which types and classes in the Python standard library support math operations but are not really numbers?</p>
  
  <p>The two that I know of are:</p>
  
  <ul>
  <li><code>list</code> in general, and strings in particular, </li>
  <li><code>tuples</code> too</li>
  <li><code>bool</code> values: this is the one surprised me</li>
  </ul>
  
  <p>Are there other ones?</p>
  
  <p>Note: to my way of thinking, <code>datetime</code>'s act like numbers to me so they're OK.</p>
  
  <p>The context is that  I'm trying to write a function that allows for interpolation on arbitrary types.</p>
  
  <p>My first idea is the following:</p>
  
  <pre><code>def weighted_combine( val1, val2, weight):
      ''' Return the weighted combination of val1 and val2
          @arg weight : 0 =&gt; ignore val2, 1 =&gt; ignore val1
                        0.5 =&gt; 50/50 mix of val1, val2
      '''
      try:
          # if I can do math, do it
          return val1+(val2-val1)*weight
      except TypeError,e:
          pass
      # otherwise pick the predominant value
      if weight&gt;0.5:
          return val2
      else:
          return val1
  </code></pre>
  
  <p>Figuring that this should work right on just about any type.  until I checked if you can do math on bool values (and numpy arrays of bool vals), so now I need to add explicit type checking for these special cases (since I want to use the "pick closer" logic for bools), so I need to know if there are other special types I'd need to consider in this case. </p>
  
  <p>Example results:</p>
  
  <pre><code>In [4]: True+(False-True)*0.2
  Out[4]: 0.8
  
  In [8]: a=scipy.array( [True, False, True])
  
  In [9]: a+(a-a)*0.2
  Out[9]: array([ 1.,  0.,  1.])
  </code></pre>