class Foo(object):
def __new__(cls, *args, **kwargs):
"""如果不覆盖这个__new__方法,也就是说不写这个__new__方法,类会从object
继承__new__方法完成返回值实例对象
"""
print "__new__方法先被调用"
tmp = super(Foo,cls).__new__(cls,*args, **kwargs)
print id(tmp)
print type(tmp)
print isinstance(tmp,Foo)
print issubclass(type(tmp),Foo)
return tmp
def __init__(self):
"""self是python默认传的值,该值是调用__new__的返回值"""
print "__init__被调用"
print id(self)
p = Foo()
print id(p)
print type(p)
已抢64983个
抢已抢27431个
抢已抢14926个
抢已抢7430个
抢已抢9384个
抢已抢18980个
抢