Tag: 新风格类

types(obj)和obj .__ class__之间的区别

type(obj)和obj.__class__什么区别? 是否有type(obj) is not obj.__class__的可能性? 我想写一个函数,一般在提供的对象上工作,使用与另一个参数相同types的默认值1。 下面的#1或#2哪个变化会做正确的事情? def f(a, b=None): if b is None: b = type(a)(1) # #1 b = a.__class__(1) # #2