Whole numbers
age = 9 keeps a number you can count and add.
02TYPES + LISTS
Picture the computer's memory as a huge shelf full of little boxes. A variable is one box with a name label on it.
WHAT GOES IN A BOX?
age = 9 keeps a number you can count and add.
height = 1.32 keeps a number with a point in it.
name = "Ana" keeps letters. Text always goes between quotes.
is_raining = True keeps True or False. Only two choices!
Four boxes, four labels. Python finds each value by its name.
A BOX CAN CHANGE
score = 0→score = 5→A box keeps one thing at a time. The newest value wins.
A BOX WITH SPACES INSIDE
snacks = ["apple", "cookie", "grapes"] puts three things in one box, each in its own little space.
Python starts counting at 0. snacks[0] is the first space.
Fun fact: In math, a row of numbers in order, like [3, 1, 4], is called a vector. In Python, we make it with a list.
A SHELF OF ROWS
board = [[1, 2, 3], [4, 5, 6]] is a list of lists: two rows with three spaces each, like an egg carton.
board[1][0] means row 1, then space 0. That is 4.
RUN IT
Guess first. Then run real Python and check.
snacks = ["apple", "cookie", "grapes"]
print(snacks[0])What will Python show?
PyBot's hint
Ready. Press Run Python.
Pyodide 314.0.3 runs CPython in your browser with WebAssembly.
Open-source under the Mozilla Public License 2.0. License
Now change one thing: Change 0 to 2. Which snack comes out? Then add your favorite snack to the list.
YOUR TURN
Try each tiny question. A wrong answer becomes something to review.
Which box keeps text?
is_happy = TrueWhat does this box keep?
colors = ["red", "blue", "green"]How many spaces does this list have?
board = [["X", "O"], ["O", "X"]]How many rows does this matrix have?
Which box keeps a decimal number?
PyBot wants the grape. Remember: the first space is number 0.
grapeOUTPUT
Want a fresh start? Clear only this page.
It can keep a number, some text, a yes or no, or even a whole list.