title: Difference between type(obj) and obj.__class__
body: <p>What is the difference between <code>type(obj)</code> and <code>obj.__class__</code>? Is there ever a possibility of <code>type(obj) is not obj.__class__</code>?</p>
  
  <p>I want to write a function that works generically on the supplied objects, using a default value of 1 in the same type as another parameter.  Which variation, #1 or #2 below, is going to do the right thing?</p>
  
  <pre><code>def f(a, b=None):
    if b is None:
      b = type(a)(1) # #1
      b = a.__class__(1) # #2
  </code></pre>