작성
·
221
0
실습 3번에서 Person .py도 실습4번의 Monitor .py와 별 차이가 없었는데
person1 = Person()
person1.__str__()
잘 작동했습니다.
헌데 Monitor.py는
monitor1 = Monitor("LG", "32", 300000, "흰색")
monitor1.__str__()
왜 이렇게 따로 추가해줘야되나요?
혹시
def __init__(self):
self.__name = "홍길동"
self.age = 35
self.hegiht = 175
self.weight = 75
self.addr = "경북"
print("Person 의 기본 생성자 호출")
Person에서는 (self)에 매개변수가 없어서 그냥 지정한 저 세트들만 고대로 출력하는거고,
Monitor 에서는
def __init__(self, company, inch, price, color):
#self.company 는 멤버 변수를 칭하는 것이고, company는 외부에서 생성자를
#호출 할대 들어오는 매개변수값으로 들어오는것을 의미한다.
self.company = company
self.inch = inch
self.price = price
self.color = color
(self, 이외 기타등등) 이 있어서 매개 변수가 받기에 차이가 생기는건가요?
답변