Python Course #3: Variables and Data Types - Storing Information

Lesson 3: Variables & Data Types

Learn how to store and work with different types of information in Python

Beginner | 15 min

What are Variables?

A variable is like a labeled box where you can store information. You can put data in it, change it, and use it later!

Think of it like:

  • A box with a label (variable name)
  • Contents inside the box (the value)
  • You can change what's inside anytime

Creating Your First Variable

# Creating variables is super easy!
name = "Alice"
age = 25
height = 5.6
is_student = True

Variable Naming Rules:

  • Start with a letter or underscore (not a number)
  • Can contain letters, numbers, underscores
  • Case-sensitive (name ≠ Name)
  • No spaces (use underscores: my_variable)
  • Avoid Python keywords (if, for, while, etc.)

Python Data Types

1. Integer (int)

Whole numbers without decimals

age = 25
year = 2025
score = -10

2. Float (float)

Numbers with decimal points

height = 5.9
price = 19.99
temperature = -3.5

3. String (str)

Text data in quotes

name = "John"
city = 'New York'
message = "Hello World!"

4. Boolean (bool)

True or False values

is_active = True
has_permission = False

Using Variables

# Create variables
name = "Sarah"
age = 22

# Use them
print("My name is", name)
print("I am", age, "years old")
Output:
My name is Sarah
I am 22 years old

Changing Variable Values

score = 10
print(score) # 10

score = 20
print(score) # 20

score = score + 5
print(score) # 25

Checking Data Types

print(type(25)) #
print(type(3.14)) #
print(type("Hello")) #
print(type(True)) #

Interactive Quiz!

Q1: Which is a valid variable name?
A) 2name
B) my_name
C) my-name
D) my name
Q2: What data type is 3.14?
A) Integer
B) Float
C) String
D) Boolean
Q3: What does this print? x = 5; x = x + 3; print(x)
A) 5
B) 3
C) 8
D) 53

Practice Challenge

Your Task: Create variables for:

  1. Your name (string)
  2. Your age (integer)
  3. Your height in feet (float)
  4. Whether you like Python (boolean)

Then print them all!

Key Takeaways

  • Variables store data
  • Python has 4 main types: int, float, str, bool
  • Use = to assign values
  • Variables can be changed anytime
  • Use type() to check data types

Great Work!

Next: Input/Output - Getting User Input
Learn how to make your programs interactive!

Post a Comment

0 Comments