Google Colab introduction  Tips

Table of Contents

Table of Contents


In this article, I want to introduce a powerful service, "Google collaboratory"(or "Google Colab" for short).
And some useful tips to use it.

What is it?

A web-base tool let us can write and execute Python in the browser.

Features

  • No settings.
  • Basically free use.
  • Easy to shared.
  • Easy to connect to Google Drive.
  • Easy for Python beginner or someone who want to make work more efficient.

How to start it?

You can use this link to start to learn.

If you want to create your new colab file, you can create it in your Google Drive.
The Steps maybe as these.

  1. Access you Google Drive Webpage.
  2. Click New button -> Click More.
  3. If you have installed Colaboratory then you can find the Google Colaboratory in the list.
  4. If you can not find it, the install Colaboratory by marketplace.
  5. If everything is OK, a new Colab file will be created.

Tips

Here will show some useful tips while coding.

(Shortcuts) Execute Code: shift + enter

shift + enter will execute the code in the cell where the cursor is located.

(Shortcuts) Insert Code Cell above: ctrl/cmd + m -> a

ctrl/cmd + m and then click a.
This will insert a new code cell above the cell where the cursor is located.

(Shortcuts) Insert Code Cell above: ctrl/cmd + m -> b

ctrl/cmd + m and then click b.
This will insert a new code cell below the cell where the cursor is located.

(Shortcuts) Change Cell to Text Cell: ctrl/cmd + m -> m

ctrl/cmd + m and then click m.
This will change the cell to text cell which is formatted using markdown.

(Shortcuts) Change Cell to Code Cell: ctrl/cmd + m -> y

ctrl/cmd + m and then click y.
This will change the cell to code cell.

(Shortcuts) Delete Cell: ctrl/cmd + m -> d

ctrl/cmd + m and then click d.
This will delete the cell where the cursor is located.

(Shortcuts) Move Cell: ctrl/cmd + m -> k/j

ctrl/cmd + m -> k: Move cell above.
ctrl/cmd + m -> j: Move cell below.

(Shortcuts) Show Keyboard Shortcuts: ctrl/cmd + m -> h

This will show all keyboard shortcuts.

(Shortcuts) Show code snippet: ctrl/cmd + alt/opt -> p

This will show code snippet panel which you can search some common and useful code.

Mount Your Google Drive

Execute the following code.

from google.colab import drive
drive.mount('/content/drive')

Copy to Github

File -> Copy to Github

Others

Google Colab automatically disconnects if it idle for more than 30 minutes.

References