📦 Variables

Learn how to store and use data in your programs using variables.

What you'll learn:

  • What a variable is and why we use them
  • How to create and assign values to variables
  • Different data types: strings, integers, and floats
  • How to use variables in output with print()

Learning Path

Follow these activities in order.

Key Vocabulary

variable

A named container that stores a value. Like a labelled box that holds data.

assignment

Giving a value to a variable using the = sign. name = "Alice"

string

Text data, written in quotes. "Hello" or 'Hello'

integer

A whole number (no decimal point). 42, -7, 0

float

A decimal number. 3.14, -0.5, 100.0

data type

The kind of data a variable holds: string, integer, float, etc.

Quick Reference

variables_examples.py
# Creating variables
name = "Alice"        # string
age = 15               # integer
height = 1.65          # float

# Using variables in print
print(name)            # Prints: Alice
print("Hello", name)   # Prints: Hello Alice

# Changing a variable's value
score = 10
score = score + 5      # Now score is 15

# Variable names: use lowercase, underscores for spaces
player_name = "Bob"    # Good!
highScore = 100        # Works, but prefer snake_case