Python: repr() vs str()

자세한 개념은 인터넷에 차고 넘치는 다른 문서들을 참고하기로 하고..
간단하게만 정리한다.

Class 를 만들고, 거기서 repr 을 재정의하지 않는다면, repr 과 str 은 같은 결과를 보여준다.
repr 은 Represent 을 뜻하는데, 말 그대로, 클래스에 대해 어떤 정보를 ‘표현’하고자 할 때 정의하여 쓰는 모양이다.
주로 디버깅을 위해 쓰인다고 하는데.. Stack Overflow 에 올라있는 mipadi 님의 글을 그대로 옮겨오면 다음과 같다.

In practice, repr is often a “lite” version of strstr might print a human-readable form of the object, whereas repr prints out information like the object’s class, usually for debugging purposes. But the usefulness depends a lot on your situation and how the object in question handles repr.

과연, 내 인생에서 repr 을 제대로 써볼 날이 올 수 있을까?

Author: 아무도안

안녕하세요. 글 남겨주셔서 고맙습니다.