-
[class] python-specific special method🐍 파이썬/파이썬 기본 문법 2022. 7. 27. 11:44
By Default, Printing An Object Is Not Helpful.
Redefine __str__ method to Improve Output.
Goal of havung __str__ is to create human-readable representation of an object.
Why doesn’t it work in collections?
Collections use __repr__ to print the contained objects !
Goal of __repr__is to create unambiguous representation of an object.
By Default, Different Objects Are Not Equal
Redefine __eq__ to Allow Equality Check!
By Default, Classes Cannot Be Hashed
Define __hash__ to Use Instances as Keys!
__hash__ must return the same value for objects that are __eq__
find out other special methods : https://docs.python.org/3/reference/datamodel.html
'🐍 파이썬 > 파이썬 기본 문법' 카테고리의 다른 글
[OOP] The Four Core Principles of OOP (0) 2022.07.28 [inheritance] 상속 with 예제 (0) 2022.07.28 [OOP] class 클래스 개념 및 구성요소 (0) 2022.07.27 [list] reference and copy (aliasing and clone) (0) 2022.07.19 [List] 자주쓰이는 리스트 메소드 정리 (0) 2022.07.19