All lessons

Variables

6 min · Python

Store values in named boxes called variables, then reuse them.

A variable is a name that holds a value, like a labeled box. You create one with an equals sign: the name on the left, the value on the right.

Once a value is stored, you can use the name anywhere instead of repeating the value. Run this to see Python remember the name and print it back.

Try it yourself

Loading editor...

Ln 1, Col 1Spaces: 4
Sign up to run itExpected output: Ada

Numbers and combining values

Variables can hold numbers too (numbers don't need quotes). You can also print more than one thing at once by separating them with a comma — Python puts a space between them.

Try it yourself

Loading editor...

Ln 1, Col 1Spaces: 4
Sign up to run itExpected output: Age: 36

Your turn

Create a variable called greeting set to the text Hello there, then print it.

Your turn

Loading editor...

Ln 1, Col 1Spaces: 4