---
# System prepended metadata

title: 01 - Variables

---



# 01 - Variables

**Notebook:** `01-variables.ipynb`

## Video

<iframe width="560" height="315" src="https://www.youtube.com/embed/JkQfd6QN5gI?si=eEEQv2VIu7ZPGO3u" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>

---

## Getting Oriented in Colab

If you've never been in a Colab before, let's walk through what we're seeing.

In Colab, there are things called **cells**, and there are two types:

### Text Cells

These have text that usually explains stuff. You can tell these because they'll have bigger words (headings). If you double-click on a text cell, you can edit it—this is written in a markup language called **Markdown**.

- Put a `#` (hashtag) in front of a word and it becomes a heading
- One `#` makes it an H1 (heading level one)
- Two `##` makes it an H2 (slightly smaller)
- Three backticks ``` turn text into a code block

### Code Cells

These have actual code that will run. You'll know it's a code cell because there's a **play button** next to it. Press play and something will happen—the code will run.

### Creating and Deleting Cells

- **Create cells**: Hover over the line between two cells and click "add code" or "add text"
- **Delete cells**: Hover over the right-hand side of a selected cell and hit the trash can

---

## What is a Variable?

A [**variable**](/glossary/coding-basics-py/variable) is a name that holds a value. That's it.

```python
name = "something"
```

The name on the left, the value on the right.

---

## Your First Variable

In this first cell, we have the word `poem`, which is a variable—and we get to choose the names of our variables. We're calling it `poem` because we're going to store a poem title in it.

**Note:** Variable names can't have spaces. If you want a two-word name, use an underscore: `poem_title` or `word_count`. This is called **snake_case**.

```python
poem = "The Raven"
print(poem)
```

When you press play:

1. It stores "The Raven" in that `poem` variable
2. Then when we [`print()`](/glossary/coding-basics-py/print) the `poem` variable, it shows "The Raven"

Go ahead and press play now. You'll see "The Raven" appear in the output below the cell.

---

## Strings

The value in quotation marks—`"The Raven"`—is called a [**string**](/glossary/coding-basics-py/string).

Anything within quotation marks is a string. That means it'll be interpreted as a string of characters, and we'll pass that string of characters around and do different things with it.

The simplest thing we can do is print it.

---

## More Variables

We can have as many variables in this notebook as we want:

```python
line = "Once upon a midnight dreary, while I pondered, weak and weary"
print(line)
```

We can store values in variables, and then put those variables together in different ways. That's going to depend on the type of variable—if it's a number, maybe we could add numbers together. If it's a string, we can put the strings together to form larger sentences or articles.

---

## F-Strings: Combining Variables

Here's one of our first kind of weird syntaxes—the types of stuff that might be off-putting if you're brand new to coding:

```python
author = "Edgar Allan Poe"
print(f"{poem} by {author}")
print(f"First line: {line}")
```

Output:
```
The Raven by Edgar Allan Poe
First line: Once upon a midnight dreary, while I pondered, weak and weary
```

Notice:

- There's an `f` in front of the quotation mark
- There are curly braces `{}` that look like handlebars or moustaches

What's happening here? Instead of saying the word "poem" literally, Python is **injecting the value of poem** into the string. Same with `author` and `line`.

This is called an [**f-string**](/glossary/coding-basics-py/f-string) (formatted string). It's a way to have a template where some words are hard-coded, and other words are variables that will show up as whatever the value of that variable is when you run the print function.

So we've essentially taken all three of our variables—`poem`, `line`, and `author`—and put them together into these print statements with template strings.

---

## Important: Variables Persist in Notebooks

One important thing to understand about Colabs: once you've played a cell earlier in the notebook and it stores something in a variable, that's going to be **available to us all the way throughout the notebook** until we change that value.

Up above we defined `poem` in the same cell that we printed it in. Down below we only defined `author`, but we're still using `poem` and `line`—and it works!

That's because once we've said `poem = "The Raven"`, that is just what `poem` is now—until we change it.

### Important notes:

- This only works *within* the notebook—if you open another notebook, just because you call something `poem` doesn't mean "The Raven" is stored in it
- Until you press play, it hasn't actually assigned that value to the variable

---

## About the Print Function

[`print()`](/glossary/coding-basics-py/print) is actually what's called a **function**. We have a whole workbook devoted to functions later on, but for now:

- Functions have a name (`print` in this case)
- You pass in some input inside parentheses
- The `print` function takes in a value and shows it to us in the console

We've been using this function the whole time—firing off that print function and shoving stuff inside of it as input.

---

## Numbers vs. Strings

In Python, variables can hold different types of data. Two fundamental types are **numbers** and **strings**.

- **Numbers** (integers, floats) are used for mathematical operations—you can add, subtract, multiply, and divide them
- **Strings** are sequences of characters—they're typically used for text

Even if a string contains digits (like `"123"`), Python treats it as text, not a numerical value, unless you explicitly convert it.

```python
# This is a number — you can do math with it
count = 5
print(count + 1)  # 6

# This is a string — even though it looks like a number!
count_str = "5"
print(count_str + "1")  # "51" (it joins the text, not adds)
```

---

## Try It

1. Create your own variables for another poem
2. Try to make your own sentence using an f-string with those variables
3. Pause the video and give it a try!

---

## Challenge: Ask Gemini About Numbers

Once you've created your template string, use Gemini right here in Colab to ask about how storing numbers in variables is different from strings.

There's a little **Gemini button** in Colab. Press it and say:

> "Can you create a text block and a couple of code blocks that teach me how storing numbers in variables is different from strings?"

Gemini will create code for you right in your notebook. You're welcome to create code with Gemini throughout this entire process—that's the vibe coding way!

But remember: make sure you're trying to **internalize** what you're learning from Gemini. Ask it follow-up questions, make sure you understand what's happening in the code. Don't just let it do the coding for you and then skip to the next notebook.

---

## Summary

In this notebook, you learned:

- A **variable** is a name that holds a value
- **Strings** are text in quotation marks
- **F-strings** let you inject variable values into text templates
- Variables **persist** throughout the notebook after you run a cell
- The **print()** function displays values to the console
- Always **ask Gemini** when something is confusing!