← Python course

Lesson 02

Variables and strings

Giving the computer a memory — names for things.

Last lesson the computer forgot everything the moment it printed it. Today we give it a memory.

Loading editor…

name = "Rodas" is a variable. Read it right to left: take "Rodas", and store it under the label name. Now anywhere below, name is "Rodas" — you don't have to retype it.

Notice age = 15 has no quotes. That's because 15 is a number (an int), not text. Quotes mean "this is a string, treat it as words, not math." Mix them up and Python will let you know.

You can glue strings together with +, or build a sentence with an f-string:

Loading editor…

That f"..." is an f-string — the f before the quotes means "look inside the curly braces and fill in the variables." It's the cleanest way to mix text and values, and you'll use it constantly.

Variables can change. That's the whole point of the word "variable":

Loading editor…

Your turn

Make three variables: your name, your age, and your favorite subject. Print a sentence using all three in one f-string.

Loading editor…

Next lesson: teaching the computer to make decisions — to do different things depending on what's true.