Overview#

This section is your introduction to the Python language itself: the basic data types, the control flow, how to write reusable functions, and how to organize code across files. The next two sections (Scientific Python and Pandas) build directly on this material.

Learning objectives#

By the end of this section, you should be able to:

  1. Use Python’s basic data types — numbers, strings, booleans — and check the type of any value.

  2. Use core data structures — lists, tuples, and dictionaries — including indexing, slicing, and basic iteration.

  3. Write conditional logic and loops to make decisions and process collections.

  4. Define and call functions with positional and keyword arguments, and explain the difference between pure and impure functions.

  5. Read and write a simple class definition — understand the role of __init__, attributes, and methods.

  6. Organize related code into a module (a .py file) and import it from a notebook.

Pages in this section#

  • Python fundamentals — types, math, conditionals, loops, lists, tuples, dictionaries.

  • Functions and classes — defining functions, namespaces, and reading classes.

  • Organizing Python projects — project structure, reproducibility, and using .py modules from a notebook.

  • Assignment 3 — practice with lists, dictionaries, and functions (notebook you’ll download, fill in, and submit).

In-class assignment — 10 points

Your in-class assignment for this section is to complete the “Try it” exercises in the lecture notebooks above. Work through them in your own copy of each notebook. To submit, push your completed notebook(s) to your week folder and post a link to each on the matching Courseworks assignment. (Your at-home assignment — Assignment 3 — is graded separately, 10 points.)

Working through the lectures#

The three lecture pages above are Jupyter notebooks. Use the download button in the top-right of each page (the ⬇ icon) to grab the .ipynb file, open it in your environment (JupyterLab on LEAP or Colab), and step through the cells. For the shorter notebooks you can also just copy-paste the cells into a fresh notebook in your environment. The Try it admonitions invite you to experiment in your own cells before moving on.