Inheritance question for class

Asked 2 weeks ago, Updated 2 weeks ago, 2 views

class cal:
    def __init__(self, one, two):
        self.one=one
        self.two=two

    def add(self):
        result=self.one+self.two
        return result

    def mul(self):
        result=self.one*self.two
        return result

    def sub(self):
        result=self.one-self.two
        return result

    def div(self):
        result=self.one/self.two
        return result

class more(cal):

    def pow(self):`result=self.one**self.two
        return result

Here, I would like to know if power of class more can be changed to ___init_ and how it changes to change it.

class inheritance

2022-09-20 15:32

1 Answers

I might have misunderstood the question I wonder if you are talking about the following.

class cal:
    def __init__(self, one, two):
        self.one=one
        self.two=two

    def add(self):
        result=self.one+self.two
        return result

    def mul(self):
        result=self.one*self.two
        return result

    def sub(self):
        result=self.one-self.two
        return result

    def div(self):
        result=self.one/self.two
        return result

class more(cal):
    def __init__(self, one, two):
        self.one = one
        self.two = two

    def pow(self):
        result=self.one**self.two
        return result

a = more(3,3)
print(a.add()) # 6 
print(a.pow()) # 27


2022-09-20 15:32

If you have any answers or tips


© 2022 pinfo. All rights reserved.