<a target="_blank" href="https://drive.google.com/file/d/1zmrBZ23qIanyy73m_hlBHYtMf-4FPZ2A/view?usp=sharing"><img src="https://www.tensorflow.org/images/colab_logo_32px.png" />Run in Google Colab</a>
<br />
#  Intro to Google Colab
Colaboratory, or "Colab" for short, allows you to write and execute Python in your browser, with
- Zero configuration required
- Free access to GPUs
- Easy sharing
Whether you're a **student**, a **data scientist** or an **AI researcher**, Colab can make your work easier.
## Getting started
The document you are reading is not a static web page, but an interactive environment called a **Colab notebook** that lets you write and execute code.
For example, here is a **code cell** with a short Python script that computes a value, stores it in a variable, and prints the result:
```python
seconds_in_a_day = 24 * 60 * 60
seconds_in_a_day
```
86400
To execute the code in the above cell, select it with a click and then either press the play button to the left of the code, or use the keyboard shortcut **Shift+Enter**. To edit the code, just click the cell and start editing.
Variables that you define in one cell can later be used in other cells:
```python
seconds_in_a_week = 7 * seconds_in_a_day
seconds_in_a_week
```
604800
This is a **text cell**. You can **double-click** to edit this cell. Text cells
use markdown syntax. To learn more, see this [markdown
guide](https://colab.research.google.com/notebooks/markdown_guide.ipynb).
You can also add math to text cells using [LaTeX](http://www.latex-project.org/)
to be rendered by [MathJax](https://www.mathjax.org). Just place the statement
within a pair of **\$** signs. For example `$\sqrt{3x-1}+(1+x)^2$` becomes
$\sqrt{3x-1}+(1+x)^2.$
Colab notebooks are Jupyter notebooks that are hosted by Colab. To learn more about the Jupyter project, see [jupyter.org](https://www.jupyter.org).
## Integration with Drive
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->Make a Copy** creates a copy of the notebook in Drive.
- **File->Save** saves the File to Drive. **File->Save and checkpoint** pins the version so it doesn't get deleted from the revision history.
- **File->Revision history** shows the notebook's revision history.
## Rich, interactive outputs
Until now all of the generated outputs have been text, but they can be more interesting, like the chart below.
```python
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5, 6, 7, 8, 9]
y1 = [1, 3, 5, 3, 1, 3, 5, 3, 1]
y2 = [2, 4, 6, 4, 2, 4, 6, 4, 2]
plt.plot(x, y1, label="line L")
plt.plot(x, y2, label="line H")
plt.plot()
plt.xlabel("x axis")
plt.ylabel("y axis")
plt.title("Line Graph Example")
plt.legend()
plt.show()
```

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](http://nbviewer.jupyter.org/github/ipython/ipython/blob/1.x/examples/notebooks/Cell%20Magics.ipynb).
```python
%%html
<marquee style='width: 30%; color: blue;'><b>Whee!</b></marquee>
```
<marquee style='width: 30%; color: blue;'><b>Whee!</b></marquee>
```python
%%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>
```

## Useful references
- [Github Markdown basics](https://help.github.com/articles/markdown-basics/)
- [marked.js library used by Colab](https://github.com/chjj/marked)
- [LaTex mathematics for equations](https://en.wikibooks.org/wiki/LaTeX/Mathematics)
- [Charts in Colaboratory](https://colab.research.google.com/notebooks/charts.ipynb#scrollTo=08RTGn_xE3MP)