Hello everybody,
Michael here, and in today’s post, we’ll do something special-a quick dive (or you could call it a Programming Byte) into another IDE you can use for all sorts of fun Python coding adventures-Google Colab! Think of this post as a long-awaited follow-up to Python Program Demo 1: Using the Jupyter Notebook (written in December 2019).
What is Google Colab?
Google Colab (short for Colaboratory) is similar to Jupyter Notebook since both can be used as Python IDEs. However, what more should you know about Google Colab, and what are its differences/similarities to Jupyter Notebook:
| Google Colab | Jupyter Notebook |
| Requires an internet connection and a Gmail account to use | Can be utilized offline and doesn’t require a special account |
| It’s easy to save your code to GitHub with one click of a button | It’s a lot harder to save your code to GitHub; version control via Git is also more challenging since Jupyter notebooks are saved as JSON files |
| It’s free to use, but if you want better computing power from Colab, better to upgrade to a paid plan | It’s always free to use, with no upgrade-to-paid-plan options |
| Certain commonly-used packages (e.g. pandas) come pre-installed with Google Colab | Jupyter will require you to install any package you wish to use (though if the package is already on your device, no need to install it again) |
| Only works with Python and HTML markdown | Works with Python, HTML markdown, R and Julia (which is a dynamic programming language) |
| There could be security risks as the code you work with in Colab is stored on Google Cloud servers | Most code is stored on your local drive, not on cloud servers |
Now that we’ve explored the gist of Google Colab, let’s see how we can use it!
Let’s start Colab-orating!
To start using Google Colab, click this link-https://colab.research.google.com/. It should take you to the Google Colab homepage, which looks something like this (as of September 2024):

- If you’re not signed in to your Gmail account, you would need to do so before signing in to Colab.
As you can see, we have landed on the Google Colab homepage-and in case you’re wondering, we’re not going to explore the Gemini API today (though feel free to do so on your own).
Now, how do we start developing? Click on File–>New Notebook in Drive to create a new Colab notebook file; doing so will open up a new tab on your browser with a blank notebook file that looks like this:
Granted, the new file will come with a boring default title like UntitledNotebook4.ipynb or something like that, but you can change the notebook’s name by clicking on the textbook to the right of the multicolored triangle icon. Note that all Colab notebooks, like Jupyter notebooks, will use the IPYNB extension. Personally, I think Exploring Google Colab works for this lesson.
Colab Coding
Once we have our Colab notebook set up, it’s time to start coding!
Here’s how we’d write and execute some code in Colab!
In this example, we executed two simple lines of code in Colab by first writing said code into a blank Colab cell before clicking the Play icon in the cell to run the code. Since the code in this screenshot was already ran, we can see the output in the white cell below. Simple, yet effective!
- If you’d like to edit the code in a certain cell, click on the code cell once to be able to edit that cell. Then click the
Playbutton in that cell to run that code.
HTML Markdown
As I mentioned earlier in this post, Google Colab can also render HTML markdown text in addition to Python code. How can we generate some HTML text?
To generate HTML text, click on the Text button on the top of the screen to add a new text cell to your Colab notebook. Once the text cell is added, you can add all the HTML text you want-the best part about Colab is that, unlike in Jupyter Notebook, you can see how the text will appear as you are typing and formatting it (Jupyter Notebook only allows you to see the text once you’re done formatting/typing it).
Once your done using the editor, click on the pencil-like icon with a slash through it to close the editor. After you close the editor, you’ll see a textbox that looks like this:
As you can see, Google Colab managed to neatly format the text according to the HTML formatting we specified earlier.
- Also, if you wish to further format the HTML text in a given text box, simply double click the text box to reopen the text editor.
A little CSS, perhaps?
Now, you might be wondering whether Colab can implement cool CSS styling (particularly inline CSS styling). The short answer is no, although I did try to do so here:
In this text cell, I tried coloring the text From the mind of Michael blue using inline CSS styling but lo and behold, that didn’t work. Apparently Google Colab doesn’t work with fancy CSS stylings:
As you can see, despite my best efforts to give this text some color, the output is a standard <h3> tagged-text.
Off to GitHub
And now, let’s see how we can send our Colab creation to GitHub!
But first, to save the notebook, click File–>Save (or use CTRL+S) to save the latest version of your notebook.
Now, how do we get our notebook to GitHub? First click File–>Save a copy in GitHub, which will take you to this screen:
Click Sign in to login to your GitHub account and continue along the sign-in process until you see this screen:
Click the Authorize googlecolab button to authorize Google Colab to connect to your GitHub account; this button will allow Google Colab to have read and write access to your GitHub public gists (which are Git repositories).
Once you click the green button, you should be taken back to your Google Colab notebook where a screen like this should appear:
In order to copy your Colab notebook to GitHub, select the Repository and its respective branch to indicate where to place the notebook copy in GitHub. Of course, feel free to change the commit message and include a link to the Colab notebook during the copying process.
Once you click OK, you should see the Colab notebook in the GitHub repository’s respective branch that you selected earlier:
As you can see, we have a copy of our Colab notebook in GitHub in the main branch of my blogcode repository (which is where I will store all the scripts from my posts). Here’s the link to the Colab notebook copy in GitHub-https://github.com/mfletcher2021/blogcode/blob/main/Exploring_Google_Colab.ipynb.
Interestingly, even though the line From the mind of Michael didn’t display blue in the Colab notebook, the blue came through here in the GitHub copy.
Thanks for reading,
Michael