Swipe
SwipeSwipe
Swipe Apps

Paths

Motivation

Information

Variables & Numbers · Lesson 7 of 11

Variables

A free lesson from Swipe Coding · Python, level 2 · updated October 2026

By the Swipe team, founded by Colin · how we make lessons

🤖
Variables here skip the type keyword entirely — Python just watches what you hand it. 🐍

A variable is a named container that stores a piece of data your program can work with and change while it runs. In Python, you never declare a type for a variable — the general pattern is simply name = value, and Python figures out what kind of data it is automatically. This is called dynamic typing: a variable's type is determined by whatever value it currently holds, and that can even change later if you assign it something new.

age = 25
print(age)
Creating a variable named age, giving it the value 25, and then printing it. No type keyword needed.
🤖
score and Score are two totally different variables here — case really does matter. 🐍

Variable names in Python must start with a letter or an underscore (_) — never a digit — and can't be one of Python's reserved keywords (like if or class). Names are case-sensitive, so score and Score are two different variables. By convention, Python developers write variable names in snake_case: all lowercase, with underscores separating words, e.g. total_score or first_name.

Fill in the blank

Python's naming convention for variables is ____, where words are lowercase and separated by underscores, such as total_score.

A variable can also be reassigned: given a new value after it already has one. The new value simply replaces the old one, and unlike statically typed languages, the new value does not even need to be the same type as before — a variable that held a number can later hold text.

lives = 3
lives = lives - 1
print(lives)  # 2

lives = "game over"
print(lives)  # now a string, and that's fine
Reassigning a variable using its own current value, then reassigning it again to a completely different type.

Python also lets you assign several variables at once on a single line by separating both the names and the values with commas. This is called multiple assignment, and it is a common, tidy way to set up related variables together.

a, b = 1, 2
print(a)  # 1
print(b)  # 2

name, age, is_student = "Maya", 21, True
Multiple assignment creates several variables in one line, matching each name to the value in the same position.
Quick check

What happens when you reassign a Python variable to a value of a different type than it held before?

True or false

In Python, you must write a type keyword before a variable name when creating it, similar to int in other languages.

Keep your streak going in Swipe Coding

Swipe through every level of Python on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.

Get the Swipe apps →