Python - 2

Python - 2: Variables

Variables store information so you can reuse it later in your program.

Your challenge: Create variables for a name and favorite food, then print both values.

✦ Python Editor
▶ Output

Create a variable

Use an equals sign to give a variable a value: name = "Alex"

The variable name goes on the left, and the value goes on the right.

Use the variable

To display the stored value, pass the variable to print(): print(name)

Do not put quotation marks around the variable name. "name" would print the word itself instead of the stored value.

Try it: Change both values, then add another variable for a favorite color.

Good Python habit: Use clear variable names such as favorite_food. Python commonly uses underscores between words.

👀 Show Example Solution
name = "Sophie"
favorite_food = "Tacos"

print(name)
print(favorite_food)

The values are stored once in variables and then reused by print().