Python Programming : A Classroom Approach.
2.3
Google Colab: Your Cloud-Based Coding Companion
Google Colab, short for
Google Colaboratory, is essentially a Jupyter Notebook that runs in the cloud and is deeply
integrated with Google Drive. Think of it as Jupyter
Notebook, but with the added benefits of:
Free access to GPUs and TPUs: Colab provides free access to powerful GPUs and TPUs, which
can significantly speed up your code, especially for machine learning tasks.
Easy sharing: Colab
notebooks are stored in Google Drive, making them easy to share with others.
No setup required: You don’t need to install
anything on your computer to use Colab. Everything
runs in the cloud.
Writing Your First Program in Google Colab:
A Step-by-Step Guide
Open Google
Colab:
Go to the Google Colab
website: https://colab.research.google.com/
You’ll need a Google account to use.
Create a
New Notebook:
Click on "New Notebook" at the bottom of the
page.
A new, blank notebook will open in your browser.
Writing the
Code:
In the first cell of the notebook, type the following
code:
print("Hello,
world!")
Running the
Code: To run the code in the cell, click on the "Play"
button to the left of the cell, or press Shift + Enter.
The output "Hello, world!" should appear
below the cell.
Understanding
Syntax and Basic Program Structure (in Colab): The
fundamentals of Python syntax remain the same in Google Colab
as they are everywhere else.
Troubleshooting Common Errors (in Colab): Just like
in Jupyter Notebook, error messages will appear below
the cell if there are any issues with your code.
Key Differences Between
Google Colab and Local Jupyter
Notebook
Environment: Jupyter
Notebook typically runs on your local machine, while Colab
runs in the cloud.
Computational Resources: Colab offers free access to GPUs and TPUs, which may not be
available on your local machine.
Storage: Colab
notebooks are stored in Google Drive, while Jupyter
Notebooks are stored on your local file system.
Setup: Jupyter
Notebook requires installation and setup, while Colab
requires no setup.
Google Colab is particularly
beneficial for AI and data science, especially for running modern AI techniques
interactively, and avoids students needing to separately configure software
packages and dependencies, since they can run notebooks shared by the
instructor.