Cheat sheet
Everything we used today, on one page. Print it or keep it open in a tab.
JupyterLab keys
| Key | What it does | In Colab |
|---|---|---|
Shift-EnterShift-Enter |
Run the cell and move to the next one | Same |
| Run the cell and stay on it | Same | |
| EscEsc and EnterEnter | Esc is command mode, for whole cells. Enter is edit mode, for typing. | Same |
| AA and BB (command mode) | Add a cell above or below | + Code and + Text |
| MM and YY (command mode) | Make the cell markdown or code | , then M or Y |
| DD DD (command mode) | Delete the cell. Z undoes it. | , then D |
| Save | Saves to Drive by itself | |
len? |
Show help for len. Works for any name. |
Same |
| Run → Run All Above Selected Cell | Run every cell above the current one | Runtime → Run before |
| Kernel → Restart Kernel… | Start fresh. Run your cells again. | Runtime → Restart session |
Only the last line of a cell shows its value. Use print() to show more.
Variables and types
| Code | What it does |
|---|---|
age = 34 |
Store a value. One = assigns. |
age == 34 |
Compare two values. Two == ask a question and give True or False. |
type(age) |
Show the data type: int, float, str, bool, list, dict |
f"I am {age}" |
Put a value inside text (an f-string) |
Names use letters, digits (0-9) and _, and can’t start with a digit.
Strings and indexing
Counting starts at 0.
| Code | Result with word = "python" |
|---|---|
word[0] |
'p' |
word[-1] |
'n' |
word[0:3] |
'pyt' (the end index is left out) |
len(word) |
6 |
Lists
| Code | What it does |
|---|---|
toys = ["feather", "string"] |
Make a list |
toys[0] |
Get an item by position |
toys[0] = "laser" |
Replace an item |
toys[0:2] |
Slice: items 0 and 1 |
toys.append("catnip") |
Add to the end. Changes the list itself. |
Dictionaries
| Code | What it does |
|---|---|
birthdays = {"Spot": "May 1"} |
Make a dictionary of key: value pairs |
birthdays["Spot"] |
Get a value by key |
birthdays["Sparky"] = "May 10" |
Add or change a pair |
[] on a list takes a position. [] on a dictionary takes a key.
Operators
| Kind | Operators |
|---|---|
| Arithmetic | + - * / (always a float) // (floor division) ** (power) % (remainder) |
| Comparison | == != < > <= >= |
| Logical | and or not |
if, for and def
if score >= 90:
print("A")
elif score >= 80:
print("B")
else:
print("Keep going")for i in range(5):
print(i)
for name in ["Bob", "Bill"]:
print(name, len(name))def add_nums(a, b):
return a + b
total = add_nums(2, 3)The colon and the indented lines belong to each other. print shows a value; return hands it back.
Methods
Dot notation: object.method(argument).
| Kind | Example | What happens |
|---|---|---|
| String method | word.upper() |
Returns a new value. word is unchanged. |
| List method | toys.append("catnip") |
Changes the list itself. Run it twice and you get two. |
Common errors
| Error | Usually means | Fix |
|---|---|---|
NameError |
A name doesn’t exist yet | Check the spelling, and run the cell that creates it |
SyntaxError |
Python can’t read the line | Look for a missing quote, bracket or colon |
IndentationError |
The indented lines don’t line up | Use the same number of spaces in the block |
TypeError |
A value is the wrong type for the operation | Check with type(), such as "5" + 5 |
IndexError |
The position doesn’t exist | Remember the last index is len(x) - 1 |
KeyError |
The key isn’t in the dictionary | Check the spelling and capitalization |
Read the last line of the message first: it names the error. The lines above it point to where it happened.
uv and conda commands
| Task | uv | conda |
|---|---|---|
| Check it’s installed | uv --version |
conda --version |
| Make the project | uv init --python 3.13 --vcs none --no-package dss-python |
conda create -y -n dss-python -c conda-forge --override-channels python=3.13 jupyterlab matplotlib (also adds JupyterLab and matplotlib) |
| Add JupyterLab and matplotlib | cd dss-python, then uv add jupyterlab matplotlib |
Done by the line above |
Start JupyterLab (run it inside dss-python) |
uv run jupyter lab |
conda activate dss-python, cd dss-python, then jupyter lab |
| Add any package, such as Polars for the EDA workshop | uv add polars |
conda install -c conda-forge --override-channels polars |
With conda, make the folder once with mkdir dss-python before the first cd dss-python.
Checked with uv 0.13.3 on October 20, 2026. The uv docs and the conda docs are the latest word.