Welcome to my field notes!

Field notes are notes I leave myself as I go through my day to day work. The hope is that other people will also find these notes useful. Note that these notes are unfiltered and unverified.

Python Tips and Tricks

tips
programming language
python
Author

TJ Palanca

Published

August 11, 2022

Object-Oriented Programming

__repr__(), __str__() methods for representing objects

Based on this answer:

  • __repr__() goal is to be unambiguous representation of your object, useful for debugging and should always be implemented (if not already),
  • __str__() goal is to be readable, almost like a “pretty print”, and is optionally implemented, and
  • __str__() of a container should use the __repr()__ of the contained objects, because then it would be too easy for the strings to muck up each other.