클래스의 상속 질문
조회수 608회
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
여기서 class more
의 pow
를 __ init __
로 바꿀 수 있는지, 바꾸려면 어떠한 형태로 변화하는지 알고 싶습니다.
1 답변
-
O_o 질문을 잘못이해한 걸수도 있는데 아래내용 말씀하시는게 맞나 싶네용
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
댓글 입력