all Python 3sysfunction
sys.displayhook()
debugging and tracing
The function the interactive interpreter (REPL) uses to show the result of an entered expression and to store it in the _ variable.
Syntax
sys.displayhook(value)
It is never called in a script: a bare expression 2 + 2 in a file prints nothing, unlike the REPL — a common cause of 'empty output' in a submitted solution. For None it shows nothing, which is why the console hides the result of print(). Replacing sys.displayhook changes how the REPL shows answers, for example with pprint; the original is sys.__displayhook__.
Examples
import builtins, sys
sys.displayhook(42) # → 42
print(builtins._) # → 42
sys.displayhook(None)
print(builtins._) # → 42
See also
Open in the full glossarydocs.python.orgReport an inaccuracy