#python #anaconda #jupyter-notebook #visual-code #html #css #javascript #http

제목class 내 super()와 self 차이?2019-12-07 17:58
작성자

===============조교님 풀이=============================

class AdvList(list):

    def removeAll(self, value):

        while value in self:

            self.remove(value)

            

    def replace(self, old, new, cnt):

        if cnt >= -1:

            while (cnt != 0) and (old in self):

                self[self.index(old)] = new

                cnt -=1



===========웹파 수강생 풀이=============================

class AdvList3(list):

    def removeAll(self,value):

        while(super().count(value)>0):

            super().remove(value)


    def replace(self,old,new,cnt):

        if cnt==-1:

            while(super().count(old)>0):

                self[super().index(old)] = new

        else:

            while(cnt>0 and super().count(old)>0):

                self[super().index(old)] = new

                cnt -=1


quiz4를 풀 때 저도 다른 수강생님 풀이처럼 super()를 쓰려고 했는데요.

base 클래스의 메소드를 써야하려면 super()로 받아와야 사용할 수 이는 줄 알아서요.


그런데 조교님 풀이보면 super()를 쓰시지 않았어요.

대신 self를 쓰셨는데 이 self가 결국 list 클래스를 의미하니까 굳이 여기엔 super()를 붙이지 않고 풀어도 문제가 없었던 건가요?



댓글