In this video course, you’ve learned the difference between official and informal string representations of Python objects. The special method .__repr__()
returns the official string representation, which is aimed at programmers as they develop and maintain a program. The special method .__str__()
returns the informal string representation, a friendlier format for the program’s user.
Now, you can distinguish between these two representations and know which one to expect in different situations. And if you haven’t been doing this already, you’ll never write another class without defining at least the .__repr__()
method to provide the official string representation.
Congratulations, you made it to the end of the course! What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment in the discussion section and let us know.