inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

임주아님의 게시글

임주아 임주아

@11681

수강평 작성수
4
평균평점
4.8

게시글 1

질문&답변

p_chapter03_02.py 에서 __max__를 추가해봤는데요

다른 예제는 모두 실행됐는데 max 한번 해보자 해서 해보니 안돼서요.. class Vector(object): def __init__(self, *args): ''' Create a Vector, example: v=Vector(5,10) ''' if(len(args))==0: self._x, self._y=0,0 else: self._x, self._y=args def __repr__(self): '''Return the vector informations.''' return 'Vector(%r, %r)' % (self._x, self._y) def __add__(self, other): return Vector(self._x + other._x, self._y + other._y) def __mul__(self, other): return Vector(self._x*other._x, self._y*other._y) def __bool__(self): return bool(max(self._x, self._x)) def __max__(self, other): '''__max__''' return Vector(max(self._x, other._x), max(self._y, other._y)) v1=Vector(1,5) v2=Vector(3,4) print(max(v1, v2)) ---실행시 오류문 TypeError: '>' not supported between instances of 'Vector' and 'Vector'

좋아요수
0
댓글수
3
조회수
315