Working with variables

Names, numbers & strings

Lesson 2 of 20 · 6 min · Module 1: Values & decisions

Give your data a name. Python figures out the type of value for you, so there is no special declaration keyword.

Start this lesson →

Free. No installation: you write and run the code in your browser, and it is checked automatically.

By the end, you’ll be able to…

  • Assign values to names
  • Perform arithmetic with integers
  • Calculate one value from another

The idea

Assign values with =. Strings are text; integers are whole numbers. You can calculate with numbers using +, -, *, and /.

language = "Python"
minutes = 10
print(minutes * 2)

01Assignment stores a value

age = 21 assigns an integer. next_year = age + 1 reads age, adds one, and stores the resulting integer under a new name.

age = 21
next_year = age + 1
print(next_year)
Output
22

02Keep the data type intentional

"21" is a string, so it cannot be added directly to the integer 1. Start with a numeric age for arithmetic. Assignment uses =; comparisons use operators such as ==.

Your turn

Set name to "Alex", age to 21, and next_year to age + 1. Print next_year.

What the checks look for

  • name is Alex
  • age is the number 21
  • next_year is 22
  • Prints 22
Try it in the editor →

Take this with you

Derive a value from the data it depends on, rather than copying the result by hand.

Learn Python Foundations for free

20 short lessons with real code and instant checks.

See the whole course →