Login
📚 Python for Introductory Statistics
Chapters ▾

1.1 Getting Started

Python is a general-purpose simple-syntax programming language created by Guido van Rossum in 1989. Python is widely used for scientific computing, data science, web development, machine learning, artificial intelligence and other advanced fields. Google, NASA, Netflix, and YouTube are some of the large organizations that use Python.

Google Colaboratory Notebook (Colab for short) is a free web-based Google product, similar to Google Docs, that requires no software installation for Python programming. A Colab Notebook is a list of cells created by adding a code or a text cell. When you create your own Colab notebooks, they are stored in your Google Drive account.

To Open a New Colab Notebook

Watch demo video

  1. Click this link
  2. Sign in with your Google account. If you are already signed in, continue to the next step. You can create a free Google account
  3. Click New Notebook from the bottom-right of the pop-up window

Note: It may open a new notebook automatically sometimes.

Note: Google Colab Notebook (Picture Below)

Colab screenshot: a new Untitled.ipynb notebook with one empty code cell; a green arrow points out the round play button at the left edge of the cell.

To Write Your First Python Code

  1. Click the code-cell next to the play button
  2. Type print("Hello, World!")

See picture below

Colab screenshot: the code cell now contains print("Hello, world"), ready to run with the play button.

To Execute(run) Your First Python Code

  1. Click the play button located before print("Hello, World!")
  2. Or click your first Python code and press Ctrl and Enter on your keyboard. Note: It is Command and Enter for Mac(Apple) computers.
  3. Hello, world! is displayed on a new line
Colab screenshot: after running the cell, the output line Hello, world! appears directly beneath print("Hello, world!").

To Edit the Code

  1. Click the code-cell with print("Hello, World!)"
  2. Start editing

Note: The Python print function takes in arguments inside parenthesis and prints(displays) them in one line. In the above code, what happens if you leave out one of the quotation marks? print("Hello, World!) or parentheses print("Hello, World!" or misspelled the word print prnit("Hello, World")? In all these cases, you will face error messages. Computer programming languages are literal and unambiguous. It expects everything to be accurate. Learning to identify and fix the causes of errors, debugging, is an important skill in programming.

To Write Your Second Python Code

  1. Click + Code in your notebook
  2. Type 10+10 in the new code cell
  3. Click the play button
  4. The output 20 is displayed on a new line
Colab screenshot: arrows highlight the + Code button in the toolbar and the play button beside a new second cell reading 10+10, whose output 20 is shown below it.

Note: In the first code above Hello, World! was in double quotation marks. But in this example 10+10 is not in quotation marks. Python recognizes anything in quote, such as, "Hello, World!" as string data type, str, whereas 10 is recognized as an integer data type, int. Decimal numbers such as 10.1 are recognized as float data type.

Note: If you prefer not to use Google Colab Notebook, you can install free Python in your computer. See appendix 1 for details.

Adapted from Python for Introductory Statistics, by Simon Aman (Truman College, City Colleges of Chicago), licensed under CC BY 4.0. Changes were made: reformatted as an accessible XYZ web edition with live in-browser code cells. License: CC-BY-4.0.