Python __new__ 与 __init__

class A(object):

    def __init__(self, a, b, c, *args, **kwargs):
        self.a = a
        self.b = b
        self.c = c

    def __new__(cls, a, *args, **kwargs):
        cls.aa = a
        return super().__new__(cls)


a = A('a', 'b', 'c')
print(a.a, a.b, a.c)
print(A.aa)

运行结果

a b c
a

你可能感兴趣的:(Python __new__ 与 __init__)