Containers with Names

A variable is a container that holds a value, with a name you choose. Once a value has a name, you can use it anywhere by that name.

Assignment means putting a value into a variable. The = sign does the storing. It is not the equals sign from math class. Read village = "Kumasi" as: the name village now holds the text Kumasi.

Creating a variable

PYTHON

village = "Kumasi"

JAVASCRIPT

let village = "Kumasi"; 
Compare → Python just writes name = value. JavaScript announces a new variable with the keyword let. Both create a container named village holding the text Kumasi.
EXAMPLE
loading editor…
YOUR TURN
Your turn → Create a second variable for your ancestral village, city, or neighborhood, and print it.
loading editor…

Syntax has to be exact. Every quote, bracket and parenthesis needs its partner, and in Python the spaces at the start of a line count. One slip and the program won't run; the message will say where.

✦ No quotes on names

print(village) prints what the container holds. print("village") prints the word village itself. Names are unquoted; text is quoted.

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: Reassignment: Values Change →
← Back