Syncing account progress…

Back

Beginner · 8 min

Names and values

Store a value in a variable and use it in a message.

Give a value a name

The = sign assigns a value to a variable. Once you assign a value, you can use its name later in the program. These two lines run from top to bottom.

city = "Ankara"
print(city)

Output

Ankara

A variable name is different from a string

Without quotes, city refers to its stored value. Inside quotes, 'city' is just text. Reassigning a variable changes the value used by later instructions.

city = "Ankara"
city = "Izmir"
print(city)
print("city")

Output

Izmir
city

Follow a variable

  1. Trace the assignments from top to bottom.
  2. Compare a variable name with the same name inside quotes.

Try it yourself

Code runs on this device. When you are signed in, drafts sync to your account.

Store and display a city

Create a variable named city with the string Ankara, then use print(city) to display its value.

Practice