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.
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
© 2024 OneMinuteCode. All rights reserved.