Skip to lesson content
navan✳THE BUILD LABPYTHON 3
0/101 complete
BUILD LAB / PYTHON/ Boot sequence
EXPERIMENT 03 / 101

Give things a name.

Store values, change them, and give your future self readable code.

BY NAVAN SAMI◷ 6 MIN READPYTHON 3

01 The idea

A variable name refers to a value. Assignment with = binds the name to that value; another assignment can bind it to a different value. Choose names that describe what a value means. Python does not require a type declaration for each name.

02 The experiment

Read it once. Predict what will happen. Then copy it into a .py file and run it in your local Python setup.

variables.py
project_name = "Orbit"
open_tasks = 4
open_tasks = open_tasks - 1

print(project_name)
print(open_tasks)
↳ EXPECTED OUTPUT
Orbit
3

03 Under the hood

  1. 1

    project_name refers to text; open_tasks refers to an integer. Python keeps track of the types of the values.

  2. 2

    The right side of an assignment is evaluated first. open_tasks - 1 produces 3, then the name is updated.

  3. 3

    Use snake_case for ordinary names. A name like open_tasks communicates more than x. Names are case-sensitive, so score and Score are different.

04 Your turn, builder

A SMALL MISSION

Create a battery_level variable with value 100. Reduce it by 15 and print the remaining level.

Reveal one possible solution +
one_possible_solution.py
battery_level = 100
battery_level -= 15
print(battery_level)

05 Check your signal

QUICK SIGNAL CHECK

After count = 3 followed by count = count + 2, what is count?

THAT’S ANOTHER IDEA IN YOUR TOOLKIT.

Experiment. Logged.

When you can explain the idea and make the example your own, mark it complete. Your log stays in this browser.

Keep exploring

Go deeper with the official Python guide ↗.

Built with curiosity. By Navan Sami. ↗Python 3 · Think. Try. Build.