How to run Python code on Google Colaboratory?

Google Colaboratory is a free Jupyter notebook environment that requires no setup and runs entirely in the cloud. It is hosted in google cloud and maintained by Google for the benefit of python coders who want to run and test python scripts using a cloud environment. In this article, we will see how to set up and run a google collaboratory cloud environment.

Opening the Python Notebook

We navigate to this google link ( It opens up the below screen. We choose the option NEW PYTHON3 NOTEBOOK from the bottom right corner as shown in the diagram below.

Python CodeOptions

On clicking the NEW PYTHON3 NOTEBOOK we get a new screen that allows us to write the code in python version 3 and also give a name to the file where this code is going to be stored. We can see the options to add a code cell and text cell etc, similar to the features we get in the jupyter notebooks.

Writing Python Code

Now we can write the python code in the code cell created above. We can import the require d libraries and write code to sue the libraries as we do in any normal python code.

Running the Python Code

Next, we can run the above code written by pressing the black run button mentioned in the top left corner above the code. The code runs for some time and the result is printed below as shown in the picture below.

Updated on: 17-Oct-2019


Kickstart Your Career

Get certified by completing the course

Get Started