인프런 커뮤니티 질문&답변
3개 이상의 연산인경우 프로세스가 궁금합니다.
작성
·
361
답변 3
0
def __add__(self, other):
return Fruit('{} + {}'.format(self._name, other._name) ,self._price + other._price)
print('total price : {}'.format((s1 + s2 + s3)._price))
0
#기존 매직메소드 밑에 추가로
def __add__(self, x):
print('Called >> __add__ Method.')
return self._price + x._price
#62번째라인에 s3을 입력후
s3 = Fruit('Apple', 1000)
#73번째라인에
print(s1 + s2 + s3)
입력하면 에러 난다고 윗분이 질문하신 것 같은데 ,
저도 해결책이 궁금해서 질문드립니다.
0
좋은사람
지식공유자
메직메소드 멀티 연산자를 받으실 때는
아래와 같이 팩킹 언패킹 등으로 dict , tuple로 받으시는게 좋습니다.
>>def test(*args, **kwargs):
>> print args # list of positional parametrs
>> print kwargs # dict of named parametrs
>>test(1, 2, test_param='t')
[1, 2]
{test_param: 't'}





