8

Lesson 8 of 20 ยท Variables

Variables โ€” Part 16

Store and use values that can change. This is part 16 of 20.

What you'll learn

You will learn that variables store values like labeled boxes, and you can read and update them.

Steps

  1. 1A variable is like a labeled box. Here, 'score' is the label and 0 is what's inside. score = 0 means 'put 0 in the box called score'.
  2. 2print('Score:', score) looks inside the box and shows what's there โ€” it would display 'Score: 0'.
  3. 3Then score = score + 1 takes the current value (0), adds 1, and puts the result (1) back in the box. Now score holds 1!
  4. 4Variables let programs remember and update information โ€” like keeping score in a game, tracking lives, or storing a player's name.

Key Terms

Variable
A named place to store a value (e.g. score). You can read it and change it.
Value
A piece of data, like a number or text. Variables hold values.
Assign
To give a variable a value using = (e.g. score = 0).
Python 3
Output
Loading Python... This may take a few seconds.

Your code runs only in your browser. No code is sent to any server. Stay safe and have fun learning!

๐Ÿ–จ๏ธ

Checkout complete lesson on Variables for 2nd Grade

Get the full Variables track as a printable PDF โ€” all lessons, worksheets, and answer keys.

View in Shop

Your Cart (0)

Your cart is empty

Browse our shop to find activities your kids will love