1

如何在不输入很多内容的情况下使用超类的实例定义子类?看:

class A():
    def __init__(self,x,y):
        self.x=x
        self.y=y

class B(A):
    def __init__(self,x,y,z):
        A.__init__(A,x,y)
        self.z=z

class1=A(2,3)
class2=B(class1.x,class1.y,5)   # Is there something easier than this, where I don't have to type class1.x, class1.y and
                                # I can just pass all the data members of class1 at once?
4

1 回答 1

0
class A(object):
    def __init__(self,x,y):
        self.x=x
        self.y=y

class B(A):
    def __init__(self,a,z):
        self.a=a
        self.z=z

class1=A(2,3)
class2=B(class1,5)
于 2017-12-24T20:18:55.670 回答