title: User defined int class that supports addition
body: <p>I want to  create a class that wraps an <code>int</code> and allows some things not normally allowed with <code>int</code> types. Here is my code:</p>
  <pre><code>class tInt(int):
      def __add__(self, other):
          if type(other) == str:
              return str(self) + str(other)
          elif type(other) == int:
              return int(self) + other
          elif type(other) == float:
              return float(self) + float(other)
          else:
              return self + other
  a = tInt(2)
  print (a + &quot;5&quot;)
  print (&quot;5&quot; + a)
  </code></pre>
  <p>The output was.</p>
  <pre><code>&gt;&gt; 25
  Traceback (most recent call last):
    File &quot;C:\example.py&quot;, line 14, in &lt;module&gt;
      print (&quot;5&quot; + a)
  TypeError: Can't convert 'tInt' object to str implicitly
  </code></pre>
  <p>So, the first print statement ran nicely, and gave what I expected, but the second one gave an error. I think this is because the first one is using tInt's <strong>add</strong> function because a appeared before + &quot;5&quot; and the second one used the string &quot;5&quot;'s <strong>add</strong> function first because it appeared first. I know this but I don't really know how to either force a's <strong>add</strong> function or allow the tInt class to be represented as a string/int/etc.. when a normal type appears before it in an operation.</p>