Overview of Colaboratory Features - Colab
Overview of Colaboratory Features - Colab
keyboard_arrow_down Cells
A notebook is a list of cells. Cells contain either explanatory text or executable code and its output. Click a cell to select
it.
There are additional options for running some or all cells in the Runtime menu.
a = 10
a
10
Text cells
This is a text cell. You can double-click to edit this cell. Text cells use markdown syntax. To learn more, see our
markdown guide.
You can also add math to text cells using LaTeX to be rendered by MathJax. Just place the statement within a pair of $
−−−−−
signs. For example $\sqrt{3x-1}+(1+x)^2$ becomes √3x − 1 + (1 + x)2 .
You can add new cells by using the + CODE and + TEXT buttons that show when you hover between cells. These buttons
are also in the toolbar above the notebook where they can be used to add a cell below the currently selected cell.
You can move a cell by selecting it and clicking Cell Up or Cell Down in the top toolbar.
Consecutive cells can be selected by "lasso selection" by dragging from outside one cell and through the group. Non-
adjacent cells can be selected concurrently by clicking one and then holding down Ctrl while clicking another. Similarly,
using Shift instead of Ctrl will select all intermediate cells.
Long running python processes can be interrupted. Run the following cell and select Runtime -> Interrupt execution
(hotkey: Cmd/Ctrl-M I) to stop execution.
https://colab.research.google.com/notebooks/basic_features_overview.ipynb#printMode=true 1/5
10/09/2024, 20:33 Overview of Colaboratory Features - Colab
import time
print("Sleeping")
time.sleep(30) # sleep for a while; interrupt me!
print("Done Sleeping")
Sleeping
---------------------------------------------------------------------------
KeyboardInterrupt Traceback (most recent call last)
<ipython-input-3-626f81edbca4> in <module>()
1 import time
2 print "Sleeping"
----> 3 time.sleep(30) # sleep for a while; interrupt me!
4 print "Done Sleeping"
KeyboardInterrupt:
!ls /bin
That !ls probably generated a large output. You can select the cell and clear the output by either:
1. Clicking on the clear output button (x) in the toolbar above the cell; or
2. Right clicking the left gutter of the output area and selecting "Clear output" from the context menu.
Execute any other process using ! with string interpolation from python variables, and note the result can be assigned
to a variable:
['Colaboratory is great!',
'Colaboratory is great!',
'Colaboratory is great!',
'Colaboratory is great!']
keyboard_arrow_down Magics
https://colab.research.google.com/notebooks/basic_features_overview.ipynb#printMode=true 2/5
10/09/2024, 20:33 Overview of Colaboratory Features - Colab
Colaboratory shares the notion of magics from Jupyter. There are shorthand annotations that change how a cell's text is
executed. To learn more, see Jupyter's magics page.
%%html
<marquee style='width: 30%; color: blue;'><b>Whee!</b></marquee>
%%html
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 450 400" width="200" height="200">
<rect x="80" y="60" width="250" height="250" rx="20" style="fill:red; stroke:black; fill-opacity:0.7" />
<rect x="180" y="110" width="250" height="250" rx="40" style="fill:blue; stroke:black; fill-opacity:0.5;" />
</svg>
import numpy as np
If you now insert your cursor after np and press Period( . ), you will see the list of available completions within the np
module. Completions can be opened again by using Ctrl+Space.
np
If you type an open parenthesis after any function or class in the module, you will see a pop-up of its documentation
string:
np.ndarray
The documentation can be opened again using Ctrl+Shift+Space or you can view the documentation for method by
mouse hovering over the method name.
When hovering over the method name the Open in tab link will open the documentation in a persistent pane. The View
source link will navigate to the source code for the method.
https://colab.research.google.com/notebooks/basic_features_overview.ipynb#printMode=true 3/5
10/09/2024, 20:33 Overview of Colaboratory Features - Colab
x = 1
y = 4
z = y/(1-x)
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
<ipython-input-14-dc39888fd1d2> in <module>()
1 x = 1
2 y = 4
----> 3 z = y/(1-x)
import numpy as np
from matplotlib import pyplot as plt
ys = 200 + np.random.randn(100)
x = [x for x in range(len(ys))]
Colaboratory is integrated with Google Drive. It allows you to share, comment, and collaborate on the same document
with multiple people:
The SHARE button (top-right of the toolbar) allows you to share the notebook and control permissions set on it.
File->Save saves the File to Drive. File->Save and checkpoint pins the version so it doesn't get deleted from the
revision history.
https://colab.research.google.com/notebooks/basic_features_overview.ipynb#printMode=true 4/5
10/09/2024, 20:33 Overview of Colaboratory Features - Colab
Commenting on a cell
You can comment on a Colaboratory notebook like you would on a Google Document. Comments are attached to cells,
and are displayed next to the cell they refer to. If you have comment-only permissions, you will see a comment button on
the top right of the cell when you hover over it.
If you have edit or comment permissions you can comment on a cell in one of three ways:
1. Select a cell and click the comment button in the toolbar above the top-right corner of the cell.
2. Right click a text cell and select Add a comment from the context menu.
3. Use the shortcut Ctrl+Shift+M to add a comment to the currently selected cell.
You can resolve and reply to comments, and you can target comments to specific collaborators by typing +[email
address] (e.g., [email protected] ). Addressed collaborators will be emailed.
The Comment button in the top-right corner of the page shows all comments attached to the notebook.
https://colab.research.google.com/notebooks/basic_features_overview.ipynb#printMode=true 5/5