为什么使用isinstance()而不是type()?
这个问题在这里已经有了答案:
让我给你一个简单的例子,说明它们可能会有所不同:
>>> class A(object): pass
>>> class B(A) : pass
>>> a = A()
>>> b = B()
  到目前为止,声明了一个变量A和一个从A派生的变量B 
>>> isinstance(a, A)
True
>>> type(a) == A
True
但
>>> isinstance(b, A)
True
>>> type(b) == A
False
你不能在这里使用子类。
  当一个子类满足接口时,为什么只限于一种类型?  如果有人想使用class mystr(str): ...某件事,你的代码仍然可以工作,并且不需要知道使用了一个子类。 
  因此,使用isinstance()是更pythonic的方法;  你的代码应该寻找支持的行为,而不是特定的类型。 
 Python 2.x的基本示例:标准字符串和unicode字符串,带有公共基类basestring : 
s = "123"
u = u"123"
isinstance(s, str) is True
type(u) == str  # something which has string nature returns False for this test
# these tests are common-pattern in Python 2.x and behaves correctly
isinstance(s, basestring) is True
isinstance(u, basestring) is True
