https://docs.python.org/3/reference/datamodel.html
3. Data model — Python 3.10.4 documentation
A class can implement certain operations that are invoked by special syntax (such as arithmetic operations or subscripting and slicing) by defining methods with special names. This is Python’s approach to operator overloading, allowing classes to define
docs.python.org
what is python special method doc 라고치면 나오는 파이썬의 수학의정석임
+ - * / % < > =< >= 등등 다있음
결론 : 매직메소드 는 C++ 오퍼레이터랑 비슷한 개념
PS>
인수 받아 올 때 이런식으로 받아오고
예외처리 해주는 방식 잘봐둘 것.
*은 포인터 X , 파이썬에선 '가변'이라는 뜻
이렇게 Vector() 해도 x,y에 0,0이 들어가게끔 예외처리가 가능함. ( 25,78,42 ) 이런건 안되고
위에처럼
self._x, self._y = args 같은 정의 코드만 없으면
밑에 처럼 가변으로 인수를 받아 올 수 있다.
'C++,python (인프런+사이트) > python 파이썬 정리' 카테고리의 다른 글
Comprehending Lists으로 Generator 만들기 + 깊복,얕복 (0) | 2022.04.01 |
---|---|
파이썬 자료형 정리 (0) | 2022.04.01 |
List Comprehension 리스트 컴프리헨션 +(딕셔너리 + 튜플) (0) | 2022.04.01 |
매직 메소드_네임드튜플 (0) | 2022.04.01 |
객체vs인스턴스vs클래쓰 & 인스턴스메서드vs클래스메서드vs스태틱메서드 (0) | 2022.03.31 |
댓글