Uncategorized

Unable to use super() with multiple inheritance in Python


as part of a practice of our Python knowledge, we are required to create a child class that inherits from A,B,C, to produce the output “The Name is Elzero”. While I managed to do it using the parent classes’ names, I couldn’t achieve the same result using super().init. I was wondering if it is even achievable in this situation, and how? Thanks

class A:
    def __init__(self, one):
        self.one = one


class B:
    def __init__(self, two):
        self.two = two


class C:
    def __init__(self, three):
        self.three = three


# Write The Class Called "Text" Here
class Text(A, B, C):
    def __init__(self, one, two, three):
        A.__init__(self, one)
        B.__init__(self, two)
        C.__init__(self, three)

    def show_name(self):
        return f"The name is {self.one}{self.two}{self.three}"


the_name = Text("El", "ze", "ro")

print(the_name.show_name())

# Desired Ouput
# The Name Is Elzero



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *