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
- Trace the assignments from top to bottom.
- 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.
Assign "Ankara" to city with =. Use the variable name without quotes inside print().