Programs remember things by giving them names.
This interactive puzzle needs more room than a phone can give it. Open this lesson on a wider screen - a laptop, desktop, or landscape tablet - to play it. You can continue reading the rest of the lesson on your phone.
Tap Step to watch each assignment attach a name to a value.
If you just ran your first Python program and you're wondering how it remembered anything between the two lines, variables are the answer. Every real program needs to hold on to values - a player's score, a user's name, a calculation result - and variables are the mechanism Python gives you for that.
A variable is a name that points at a value. You write the name once with =, and after that Python knows what you mean whenever you use the name.
name = "Ada"
age = 36Read = as "gets", not "equals". The first line says: the name name gets the value "Ada". That is assignment, not comparison. Once this line runs, anywhere you say name later in the program, Python substitutes "Ada" for you.
Think of it like giving someone a nickname. After you introduce your friend Alexandra as "Al", everyone in the room can say "Al" and know who you mean. A variable does the same thing for values in your program.
Every value in Python has a type. Python figures the type out from how you write the value:
str is text, always in quotes: "hello", 'Ada'. Either quote style works. Pick one.0, 42, -7.True or False. Capital first letter, no quotes.Comparing two values also gives you a bool. 3 == 3 evaluates to True. 3 == 4 evaluates to False. You'll lean on that anywhere you want a yes-or-no answer.
You also have for decimal numbers like 3.14. You'll see floats in the next lesson; this one sticks with the three above.
You can ask Python what type a value has with :
type("Ada") # <class 'str'>
type(36) # <class 'int'>
type(True) # <class 'bool'>
type(3 == 3) # <class 'bool'>Pass the variable's name to and Python prints the value:
name = "Ada"
print(name) # AdaYou can pass several values separated by commas. Python puts a space between them:
print(name, "is awesome") # Ada is awesomename = value attaches a name to a value. = is assignment ("gets"), not comparison.str is text, int is whole numbers, bool is True/False.type(value) tells you the type.