Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
实际上,Python中带参数的多重继承在没有指针的情况下是不起作用的_Python_Python 3.x - Fatal编程技术网

实际上,Python中带参数的多重继承在没有指针的情况下是不起作用的

实际上,Python中带参数的多重继承在没有指针的情况下是不起作用的,python,python-3.x,Python,Python 3.x,我想你想要的是: class First: def __init__(self, x): self.x = x print("first") def __str__(self): return " " + str(self.x) class Second: def __init__(self, y): self.y = y print("second") def __s

我想你想要的是:

class First:
    def __init__(self, x):
        self.x = x
        print("first")

    def __str__(self):
        return " " + str(self.x)


class Second:
    def __init__(self, y):
          self.y = y
          print("second")

    def __str__(self):
        return " " + str(self.y)


class Third(First, Second):
    def __init__(self, x, y, z):
          Second(y)
          First(x)
          self.z = z
          print("third")

    def __str__(self):
        return Second.__str__(self) + " " + str(self.z)

o = Third(12, 6, 5)
现在您可以执行以下操作:

class Third(First, Second):
    def __init__(self,x,y,z):
          Second.__init__(self, y)      # initializes Second subclass
          First.__init__(self, x)       # initializes First subclass
          self.z=z
          print("third")
    def __str__(self):
        return Second.__str__(self)+" "+ str(self.z)

你能澄清一下你的具体问题吗?
Second(y)
-->这意味着什么?@IvanVinogradov:请随意发布另一个答案。
>>> o = Third(12,6,5)
second
first
third
>>> print(o)
 6 5
>>> print(o.x, o.y, o.z)
12 6 5