Why Python?
Python is the lingua franca of machine learning. Its readable syntax and massive library ecosystem make it the go-to language for data science. As a designer learning ML, you don't need to become a software engineer — but knowing the basics will let you prototype, explore data, and speak the same language as your engineering team.
Core Data Structures
Tuples — Immutable Sequences
A tuple is like a list that can't be changed after creation. Defined with parentheses:
coordinates = (42.3601, -71.0589)
land_cover = ("forest", "urban", "water")Key behaviours:
- Immutable — you can't update existing elements
- Slicing uses
start:stop(stop is excluded) - Exception: if a list lives inside a tuple, the list's contents can be modified
Tuple unpacking lets you assign each element to a variable in one line:
field_data = ("Auckland", "residential", 2024, "clean")
city, land_use, year, status = field_data
# Use _ to skip values you don't need
city, _, _, status = field_dataDictionaries — Key-Value Pairs
Dictionaries store data as key-value pairs. They're how you'll work with structured data constantly:
sample = {"location": "Wellington", "pH": 7.2, "status": "clean"}
# Access values
sample["pH"] # 7.2
# Useful methods
sample.keys() # all keys
sample.values() # all values
sample.items() # key-value pairs
# Update
sample.update({"temperature": 18.5})
# Delete
del sample["status"]
# Remove and return last item
last = sample.popitem()Sets — Unique Collections
Sets automatically remove duplicates. Defined with curly braces:
readings = {7.2, 6.8, 7.2, 7.5, 6.8}
# Result: {7.2, 6.8, 7.5}remove()raises an error if the element doesn't existdiscard()silently does nothing if the element is missing- Use
&for intersection (elements in both sets)
Essential Python Libraries
Python's power comes from its libraries. Install them with pip install:
# Import the entire library
import math
# Import a specific function
from math import sqrt
# Import with an alias
import math as m
# Import everything (use sparingly)
from math import *Libraries You'll Use Most
| Library | Purpose |
|---|---|
| NumPy | Numerical computing, arrays, matrix operations |
| Pandas | DataFrames, data manipulation, CSV handling |
| Matplotlib | Basic plotting and visualisation |
| Seaborn | Statistical visualisation (built on Matplotlib) |
| Scikit-learn | ML algorithms, model training, evaluation |
| random | Random number generation |
| os | File system operations (os.getcwd() for current directory) |
Pro Tip
In Jupyter notebooks, you can run shell commands by prefixing with !:
!pip install pandasThis is handy for quick installs without leaving your notebook.