30 Days of Python #1: Start Programming Right in Your Browser (Google Colab Edition)
"Reading Data" is a series on Python and machine learning for clinicians and medical researchers. We start by acquiring programming skills to build the ability to "read and interpret" your own data. In this first installment, #1, we take the first step: opening Google Colab in your browser and running your first piece of code. No installation or complex configuration is required. It takes 5 minutes: 3 minutes to read, 2 minutes to try it out.
The experience of getting discouraged by "environment setup"
I remember once deciding that it would be good to know how to program, so I opened an introductory book.
The first page said, "Let's start with environment setup." I followed the instructions to install some software and proceeded as the screen directed, but then unfamiliar English errors appeared in red text. When I tried the solutions I found by searching, yet another error popped up.
Before I had written a single line of code, the night had grown late, and I quietly closed my laptop.
—Have you ever had an experience like that?
It is not your fault. Many introductory books have simply been quietly shaking off readers at this very first hurdle.
Key Points
By using Google Colab, you can run Python in your browser without any installation. All you need is a Google account.
Code is written in boxes called "cells" and executed by pressing the play button (or Shift + Enter). The results are displayed immediately below.
Start by running just one line of calculation. Programming is sometimes nothing more than the patient repetition of "writing and running" code.
1. Open Colab
Click the link below to open it in your browser.
Next, log in with your Google account, and while logged in, click "New notebook." With just this, you are ready to write and run code.
If you do not have a Google account, you can create one from the link below and then log in.
The long, rectangular box you see in the center of the screen is a "cell." This is where you write your code.
We recommend reading on your smartphone during spare time and using a computer for hands-on practice.
Since Colab is a website, you can open and run it from a smartphone. However, due to the need to input symbols and display tables, hands-on practice is much easier on a computer. We recommend using your smartphone to read during spare moments and your computer when you are ready to actually try the code.
2. Run your first code
Try typing the following line exactly as it is into the cell.
1 + 1Once you have finished typing, press the play button (▷) on the left side of the cell. Alternatively, you can press Shift + Enter on your keyboard. You will get the same result.
It should have displayed like this right below the cell you just used.
2Congratulations. You have just run your first Python program. This is your first step.
It might sound like an exaggeration, but this flow of "writing in a cell, executing it, and seeing the result below" is the foundation for everything we will do over the next 30 days.
Even when building machine learning models, what you are doing is ultimately the same—writing in a cell, running it, and reading the results. It is nothing more than that repetition.
3. Displaying Text
You can handle not just calculations, but also text. Add a new cell (click "+ Code" near the top left), write the following, and execute it.
print("Hello, 読むデータ")If it appears like this below, you have succeeded.
Hello, 読むデータprint( ) is a command that means "display the contents of the parentheses." It is one of the most basic tools you will use many times from now on. The rule is that the text inside must be enclosed in double quotation marks " ". For now, you can just accept that "that is how it works."
Today's Practice (2 minutes)
Add a new cell (click "+ Code" on the screen) and try the following two things.
Execute 100 * 7 and verify that the result is 700.
Replace "Your Name" in print("Your Name") with your own name, execute it, and verify that your name is displayed.
Summary of Today
Open Google Colab in your browser, write code in a cell, and execute it. That is all there is to the entrance of programming. Rest assured, you have already crossed the line that you previously thought was "a story from another world." You are different from who you were yesterday.
Next time, Part 2: "Making the Computer Remember"
We will learn about "variables," which allow you to name and store numbers and text. This is the first step in handling data.
