This is deliberate, since all expressions return something, even if it is only None
. You'd see nothing but None
in your interpreter.
You can explicitly show the return value with repr()
or str()
, or by printing (which calls str()
on results by default):
>>> y = None
>>> repr(y)
'None'
>>> str(y)
'None'
>>> print repr(y)
None
>>> print y
None
print repr()
would be closest to what the interpreter does if an expression result is not None
.
The regular Python interpreter uses sys.displayhook()
to display interpreter expression results; the IPython interpreter uses it's own hook to do this, but this hook explicitly ignores None
.
You can certainly use your own wrapper, the following hook delegates to a pre-existing hook and always displays None
, regardless:
import sys
_chained_hook = sys.displayhook
def my_displayhook(res):
_chained_hook(res)
if res is None:
sys.stdout.write('None\n')
sys.displayhook = my_displayhook