Jupyter Notebook: command for hide the output of a cell?

In my notebook, I have a cell returning temp calculation results. It's a bit long, so after it is run, I want to hide it and when needed, to show it.

To do it manually, I can double click the left side of the output, to hide it

enter image description here

After double click enter image description here

But is there any way I can do this by code? For example,

the last line of the cell, use a command like %%hide output, and the output would be hidden after finished running.

Additionally, can I get this feature in output HTML?


Add ; by the end of the cell to hide the output of that cell.


In the newer versions(5.0.0 at the time I'm writing this), pressing o in the command mode hides the output of the cell in focus. The same happens if you triple click in front of the output.

o is

  • the first letter in the word "output" or
  • lower case of 15th letter in the alphabet

You can add %%capture to the beginning of the cell.

Jupyter provides a magic cell command called %%capture that allows you to capture all of to outputs from that cell.

You can use it like this:

%%capture test print('test')

test.stdout => 'test\n'

https://ipython.readthedocs.io/en/stable/interactive/magics.html


In newer versions of Jupiter Notebook, select the desired cell, make sure you're in command mode and then on the menubar press Cell > Current Outputs. You have then three options:

  • Toggle (press O in the command mode to apply the same effect)
  • Toggle Scrolling (the default output)
  • Clear (to clear the output all together)

Image to Menubar Options

Additionally, you can apply the same effect to all the cells in your document if you chose All Output instead of Current Output.