A Guide to Google Colab

Learn more about using Google Colab in CodeHS

Mac Staloch avatar
Written by Mac Staloch
Updated over a week ago

Google Colab, short for Google Colaboratory, is a free cloud service provided by Google that allows users to run Python code real-time in a browser-based environment. It offers a convenient way to write, execute, and share Python code along with its output. Google Colab is particularly popular for machine learning applications due to its seamless integration with popular libraries such as TensorFlow.


Accessing Google Colab

If your school uses Workspace for Education for their Google services, you may need to work with your district’s technical administrator to ensure your students can access Google Colab. Depending on your district’s configuration, you may need to obtain parental consent for students' (under the age of 18) use of Additional Services with their Google Workspace for Education account. This can be achieved with this notice template. Please be sure to include Colab in the list of additional services. More information on this can be found on the Google Colab FAQ page.

Key Features

Free Access: Google Colab is free to use and provides access to a high-performance computing environment without the need for any setup or configuration and can be used to extend functionality beyond the CodeHS platform. Students need to have a Google account, but it can be a school Google account.

GPU and TPU Support: Users can leverage Google's GPUs (Graphics Processing Units) and TPUs (Tensor Processing Units) for accelerating computation, especially useful for training deep learning models. This allows for programs like machine learning models to run much faster.

Integration with Google Drive: Google Colab seamlessly integrates with Google Drive, allowing users to save and share their Colab notebooks directly from Google Drive. Students can save their files and directly share with their teacher.

Pre-installed Libraries: Google Colab comes pre-installed with popular Python libraries and frameworks such as TensorFlow so that the environment is ready for students without needing to install additional Python libraries.

Using Google Colab with CodeHS

Some CodeHS courses use Google Colabs because they allow us to extend the capabilities beyond what is available in the CodeHS IDE. A good example of this is the AI courses that use TensorFlow. These Colabs are read-only files and students will need to save a copy to their Google Drive accounts to work on them.

For an overview of Google Colabs in CodeHS and to verify that your school has access, try this Introduction to Colab notebook.

Writing and Executing Code:

  • Google Colab provides code cells where you can write and execute Python code.

  • To execute a code cell, either click the play button next to the cell or press Shift+Enter.

  • Results and output will be displayed directly below the code cell.

Saving and Sharing Notebooks

Once saved to your Google Drive, Google Colab notebooks can be shared with others. This is a great way for teachers to review student work.

Using GPUs and TPUs

  • GPUs and TPUs greatly decrease runtime, especially when using machine learning models. It is important to update the runtime type before running TensorFlow models.

  • To use GPUs or TPUs in Google Colab, go to "Runtime" > "Change runtime type" and select the desired hardware accelerator from the dropdown menu.

  • Note that while Google provides free access to GPUs and TPUs, usage may be subject to limitations based on availability and usage patterns.


Still have questions? Contact our team at hello@codehs.com to learn more!

Did this answer your question?