Naver Boostcamp AI Tech/Python

Magic Method

gukbap 2021. 8. 3. 21:56
반응형
def __str__ (self):
    return 'haha'

이러면 print 함수 같이 str 형태의 무언가를 반환할 때 해당 인스턴스는 오버라이딩된 해당 함수를 통해 haha를 반환한다.

add 같은 것도 있다.

ref : https://zzsza.github.io/development/2020/07/05/python-magic-method/

반응형