Is display() built in, i.e. a predefined global?

This is an interesting question. The answer for the first question is easy to check in IPython terminal:

> 'display' in dir(__builtin__)
True

Why? According to the IPython changelog:

The display() function is now available by default in an IPython session, meaning users can call it on any object to see their rich representation. This should allow for better interactivity both at the REPL and in notebook environment.

Which also explains why that line is not redundant in certain applications:

Scripts and library that rely on display and may be run outside of IPython still need to import the display function using from IPython.display import display.

How? It looks like IPython modifies builtins by injecting display and __IPYTHON__ constant:

When? Since version 5.0 so for quite a while now. See https://github.com/ipython/ipython/pull/10596 for more context.

2 Likes