Olivier Verdier Olivier Verdier - 8 months ago 24
Python Question

What happens during a Jupyter notebook evaluation?

I've always thought that Jupyter simply printed out the

of an object, but that is not the case.

Here is an example. If I evaluate this in a notebook:

obj = type(2)

I just get:

If I do instead


I get:
<class 'int'>

So: what is the Python instruction to simulate what the notebook does during the evaluation of a variable?


Jupyter/IPython uses a rather complex pretty printer. Concerning your example of int, it has a printer for classes/type.

Basically what it does is it gets the class' name via cls.__qualname__ (py3) or cls.__name__ (py2&3) and the module via cls.__module__, and prints them as <module.name>. For builtins, the module name is silently ignored.