Why you need to clear output in Colab
Google Colab notebooks accumulate output as you run cells — printed text, charts, error messages, and data previews all stack up and make your notebook harder to read. Clearing output removes all the visible results from your cells without deleting the code itself, which is useful when you want to share a clean notebook, start fresh before running new experiments, or reduce file size before saving.
The output stays in your notebook file even after you close it, so clearing is something you do deliberately, not something that happens automatically. Colab gives you three ways to do this: clear one cell at a time, clear all output at once, or use code to clear output programmatically.
Key Takeaways
- Right-click any cell's output area and select "Clear output" to remove just that cell's results without touching the code.
- Use the Edit menu and choose "Clear all outputs" to remove every output from your entire notebook in one action.
- The keyboard shortcut Ctrl+M then O (or Cmd+M then O on Mac) clears output from the currently selected cell.
- Clearing output does not delete your code — only the visible results disappear, and your code runs the same way next time.
- Use the IPython magic command %reset_selective -f out inside a cell to clear output programmatically when you need it as part of your workflow.
Clear output from a single cell
The fastest way to remove output from one cell is to right-click directly on the output area — the space below the code where the results appear. A small menu will pop up with the option "Clear output". Click it and that cell's output disappears immediately while your code stays intact.
If you prefer keyboard shortcuts, click anywhere in the cell (code or output area) to select it, then press Ctrl+M followed by O (on Windows or Linux) or Cmd+M followed by O (on Mac). The output vanishes without opening any menus. This method works even if you have multiple cells selected — it clears output from all of them at once.
Clear all output from your entire notebook
To remove every output from every cell in your notebook at once, click the Edit menu at the top of the page. A dropdown list appears. Look for the option that says "Clear all outputs" and click it. Colab will scan through your entire notebook and remove all visible results in seconds.
This action cannot be undone, so use it only when you are certain you want to start fresh. Your code remains unchanged — only the output disappears. This is the standard way to clean up a notebook before sharing it with someone else or before you commit it to version control.
Use code to clear output during your workflow
If you want to clear output as part of your analysis — for example, to remove clutter before running a new section of code — you can use the IPython magic command %reset_selective -f out. Type this command into a cell by itself, run it, and all output from previous cells disappears.
This approach is useful when you are testing different approaches to a problem and want to see only the results from your latest attempt. The command clears output but leaves all your variables and data in memory, so your code continues to work normally. You can also use from IPython.display import clear_output at the top of a cell, then call clear_output() inside a function or loop to clear output at specific moments in your code.
What happens to your code when you clear output
Clearing output does not change your code in any way. Every line of Python you wrote stays exactly where it is. The next time you run a cell, it produces output again just as it did before. Think of clearing output as hiding the results, not erasing them.
This is why clearing output is safe to do at any time. You can clear, run your cells again, and get the same results. The only thing that actually disappears is the visible text, numbers, and charts that appeared below your code.
When to clear output before saving or sharing
Colab notebooks with large amounts of output take up more storage space and can be slower to load when you share them. If you plan to save your notebook to Google Drive or download it as a file, clearing all output first makes the file smaller and faster to open. This is especially important if your notebook contains many charts, large data previews, or error messages from debugging.
When sharing a notebook with a colleague or posting it publicly, a clean notebook with no output is often easier to read because the viewer can run the cells themselves and see the results. It also signals that you have tested the code and it runs without errors — if you leave error messages in the output, readers may assume the notebook is broken.
Clearing output in notebooks you download or convert
If you download your Colab notebook as a .ipynb file (the standard Jupyter format), the output is included in the file. You can clear it in Colab before downloading, or you can use Jupyter on your own computer to open the file and clear output there using the same Edit menu method. Some people also use command-line tools like nbstripout to remove output from .ipynb files automatically, though that requires installing Python packages on your machine.
If you convert your Colab notebook to a Python script (.py file), output is not included in the conversion anyway — only your code transfers over. So conversion is another way to get a clean version of your work without the clutter.
Frequently Asked Questions
Does clearing output delete my variables or data?
No. Clearing output removes only what you see on the screen. Your variables, imported data, and everything in memory stays intact. If you run a cell again after clearing its output, the code executes the same way and produces the same results.
Can I undo clearing output?
No, clearing output cannot be undone. If you cleared output by mistake, you will need to run the cells again to regenerate it. This is why the Edit menu option is called "Clear all outputs" — it is permanent. Use Ctrl+Z or Cmd+Z to undo other actions, but not this one.
What is the difference between clearing output and deleting a cell?
Clearing output removes only the results below a cell's code. Deleting a cell removes the code itself and everything associated with it. If you want to keep your code but hide the results, clear output. If you want to remove the code entirely, delete the cell.
Why does my notebook still show output after I cleared it?
Make sure you clicked the correct option in the Edit menu — "Clear all outputs" removes everything, while "Clear output" (from the right-click menu) removes only one cell. Also check that you are looking at the current version of the notebook; if you cleared output but did not save, refreshing the page may reload the old version with output still visible.
Does clearing output affect how my code runs the next time?
No. Your code runs identically whether output is present or cleared. Clearing output is purely visual — it does not change the code, the variables, or the results you get when you run cells again.