Reading: Introduction to Python, Variables, and Lists


Getting started with Python (Using Google Colab)

Google Colab is a cloud-based coding network that allows us to code using Python without downloading any software to our computers. On Google, search "colab" and that will take you to a blank Colab notebook. This is a tool like Google Sheets or Google Docs that can be found in your Google Drive.

We use Colab because it is free, easy to use, and you can access your notebooks from any computer with internet access. It also means that you don't have to worry about installing Python or any libraries on your computer and keeping them up to date. Later in the course, we will provide instructions on how to install Python and Jupyter Notebooks on your own computer if you want to have that capability. All of the class assignments can be done in Colab.

You will be doing all your coding assignments in Colab. https://colab.research.google.com/. You will need a Google account to use Colab. If you do not have one, you can create one for free. In most cases, we will give you a link to a Colab notebook that we have created for the assignment. You can then make a copy of the notebook and do your work in your copy.

There is a "Welcome to Colab" notebook that will give you a brief overview of how to use Colab. You can also find many tutorials on YouTube - however, we will be going over the basics in class.

The text book either has you create a .py file or use the Python console to write and run your code. You will be using Colab instead. You can create a new cell in Colab and write your code there. Then run the cell to see the results, just like you would in the Python console as described in the book. You can ignore the parts of the book that talk about creating a .py file or using the Python console. If you have any questions about using Colab or how it is different from the book, please ask in class.

Storing and Sharing Your Colab Notebooks

Google Colab automatically saves your notebooks to your Google Drive. You can create a folder in your Google Drive to store all your class notebooks.

When you are ready to turn in an assignment, you will need to share the notebook with us. To do this, click the "Share" button in the top right corner of the Colab notebook. In the "Share with people and groups" window, click "Copy link" at the bottom. Make sure that the link is set so that "Anyone on the internet with the link can edit". If it is not, click on the dropdown that says "Restricted" and select "Anyone with the link". Then click on the dropdown that says "Viewer" and select "Editor". Now click "Copy link" again. You can then paste this link into the assignment submission form.

For organizational purposes, please rename your notebook to include the assignment name and your name just like in the Excel part of the class. You can rename the notebook by clicking on the title at the top of the page. We encourage you to create folders on your Google Drive to keep your notebooks organized. By default, Colab saves your notebooks in the main directory of your Google Drive. You can move them to a different folder by dragging and dropping them in your Google Drive, or doing a "save as" and putting them in the correct folder. Be careful with saving as, as it will create a copy of the notebook and you can end up with multiple versions of the same notebook.

Pre Class Reading Assignment

On the O'Reilly's website read Chapters 2 and 3 in Python Crash Course, 3rd Edition.

Here is a direct link to the reading:
PCC Chapter 2: Variables and Simple Data Types
PCC Chapter 3: Introducing Lists

Click here for a refresher on how to access the O'Reilly's website. Once you have signed in, the links above will take you directly to the chapters.

You will learn more if you follow along in a Colab notebook as you read the chapters. The exercises at the end of each chapter will be part of your pre-class quiz challenge. In the book, they have you write the code in the python consol or a text editor, but you will be using Colab. You can just create a cell in the Colab notebook and write your code there. Then run the cell to see the results, just like you would in the Python console as described in the book.

Things to Look Out For

  • In Python, square brackets [] indicate a list, and individual elements in the list are separated by commas.
  • Python considers the first item in a list to be at position 0, not position 1. To access an element in a list, write the name of the list followed by the index of the item enclosed in square brackets.
  • There are many ways to organize a list, you can use the sort method or the reverse method.
  • How do you add something to the end of the list and how do you add something to the middle of the list?
  • What is the difference between deleting an item, popping or removing it?
  • A list is always enclosed in a set of square brackets.
  • A list can be composed of all variable types; integers, strings, or floats.
  • Watch out for the different methods to edit lists, those will be used in the in-class workbook and homework!

Pre-Class Quiz Challenge

Open a new Colab notebook and do the following:

Exercises 1 - From Chapter 2

Create 3 different types of variables:

  • String
  • Integer
  • Float

Label each variable with a comment so that it is clear what type of variable it is.

Exercises 2 - From Chapter 3

In the same Colab notebook, complete Exercises 3-4, 3-5, and 3-6 found in chapter 3 of the textbook.


Turning in/Rubric

REMINDER - For this class, you will only turn in the links to your colab notebooks. You will get a 0 for this assignment if you turn in a python file or a link that is not correct, wrong assignment, or does not give editor permission.

Rubric:

Item Points Possible
Total
3

The following is not a part of the rubric, but specifies how you can lose points. For example: if you fail to share your link correctly.

Reasons for Points Lost Amount
Link shared incorrectly -10%