In IPython you can have alternative representations of the an object, as seen here. However I was unable to find a bare bones example of an implementation of the alternative display logic. Obviously you can do more with it than what I show here but I thought a simple demonstration would be useful.

For some background, a $\text{__repr__}$ method in Python will return a text representation of an object. Since everything is an object in Python this is how Python returns output when displaying a string object like 'Hello world' e.g. "Hello world" is returned or for an int object like 5, "5" is returned. IPython extends this idea to more than mere text representations to include SVG, JPG, PNG, LaTex, HTML, and JSON representations. This is how, for instance, a pandas dataframe can be displayed as an HTML table. IPython's display methods are used to display all rich representations in a Notebook.

There is a hierarchy of display order, which means if IPython can return a richer display format it will pick the highest in the hierarchy. The lowest is plain text, followed by JSON, PNG, JPEG, SVG, LaTeX, and finally HTML. However, this display order can be overridden by using a specific display method, display_PNG for when an object has both a PNG and a LaTex repr methods.

The following is a simple example showing some repr methods followed by an example using an override call.