Legends ofPythos
Claim your name
Python Basics

Storing values in variables

Lesson 3 of 13

Watch the lesson1:02 · with Sigrid
Imagine a labeled box where you can put something inside and take it out later. That is exactly what a variable does. It holds a value under a name so you do not have to repeat the raw number or text every time.

Creating a variable

# Create a variable called score and store 10
score = 10
print(score)
The box 'score' now holds the number 10.
The = sign is assignment. It does not mean "equals" like in math. It means: put the value on the right side into the name on the left side.

You can store different kinds of values:
  • Numbers without decimals are integers (int)
  • Numbers with decimals are floats (float)
  • Text is a string (str)
  • True or False is a boolean (bool)

Changing the value

# Start with 5
lives = 5
print(lives)

# Change it to 4 (lost a life!)
lives = 4
print(lives)
The same name now points to the new value.
When you reassign, Python simply updates what that name refers to. The old value is gone unless you saved it somewhere else.

Naming tip: Use snake_case for multi-word names. That means lowercase letters with underscores between words: player_score, not PlayerScore or playerscore. It reads clearly and follows Python conventions.

Checking the type

# See what kind of value a variable holds
age = 25.0
print(type(age))

name = "Ada"
is_adult = True
print(type(name), type(is_adult))
<class 'float'>, <class 'str'>, <class 'bool'>

Your turn

0 of 2 solved

Exercise 1

+20 XP
Create three variables:
  • player_name should store your favorite name as a string.
  • level should store the number 7 (an integer).
  • is_ready should store True (a boolean).
Write your Python here.

Run your code to check it against the tests.

Exercise 2

+20 XP
Create a variable temperature and store the float value 98.6.

Print its type using type().

Then reassign temperature to 104.5 and print it again.
Write your Python here.

Run your code to check it against the tests.