Module 1 · Lesson 1 of 8

Variables & Data Types

Every program works with data. In this lesson you'll learn how Python stores, labels, and works with different kinds of information.

Create variables and assign values
Identify strings, integers, and floats
Use type() to inspect data types
Convert between types with casting

What Is a Variable?

Think of a variable as a labeled container. You give it a name, and you store a piece of data inside. Later, you can use the name to retrieve or change what's stored.

💡 Key Concept

In Python, you create a variable with the = operator. The name goes on the left, and the value goes on the right.

example.py
# Creating variables
player_name = "Ada"
score = 42
health = 98.5

print(player_name)   # → Ada
print(score)         # → 42

Variable names in Python follow a few rules: they must start with a letter or underscore, can contain letters, numbers, and underscores, and are case-sensitive — so Score and score are two different variables.

The Three Core Data Types

Every value in Python has a type that tells Python what kind of data it is and what you can do with it.

Strings — str

Text data, wrapped in quotes. You can use single quotes 'hello' or double quotes "hello" — both work identically.

Integers — int

Whole numbers with no decimal point: 7, -3, 1000.

Floats — float

Numbers with a decimal point: 3.14, -0.5, 100.0.

🔍 Checking types

Use type() to find out what kind of data a variable holds:
type("hello")<class 'str'>
type(42)<class 'int'>
type(3.14)<class 'float'>

⌨️

Challenge 1: Variables Warm-Up

Easy

Let's practice creating variables. Complete the code below so all three print statements produce the correct output.

Instructions: Create three variables:
name — a string with your name (any name is fine)
age — an integer
gpa — a float
Remember: strings need quotes ("Ada"), integers are whole numbers (25), and floats have a decimal point (3.7). Assign each on its own line above the print statements.

Type Conversion (Casting)

Sometimes you need to convert data from one type to another. Python makes this easy with built-in functions:

casting.py
# String to integer
user_input = "25"
actual_number = int(user_input)
print(actual_number + 5)      # → 30

# Integer to string (for concatenation)
score = 100
print("Score: " + str(score))  # → Score: 100

# Float to integer (truncates decimal)
print(int(3.9))               # → 3
⚠️ Common Pitfall

You can't concatenate a string and a number directly. "Score: " + 100 will cause a TypeError. You must convert the number first: "Score: " + str(100).

🔍

Challenge 2: Type Detective

Easy

Use the type() function to figure out the data types of several mystery values. Store each type name as a string.

Instructions: For each mystery value, set the corresponding answer variable to the correct type name as a string — one of "str", "int", or "float".
Look carefully at each value! Does it have quotes around it? Does it have a decimal point? 42 is an int, but "42" has quotes so it's a str. 42.0 has a decimal point, so it's a float. What about "True"?
🎮

Challenge 3: Build a Player Card

Medium

Combine your variable and type conversion skills! Build a formatted player card string using concatenation and casting.

Instructions: Using the provided variables, create a variable called player_card that produces this exact output when printed:

Player: Nova | Level: 7 | HP: 85.5

You'll need to use str() to convert the numbers!
You need to join strings together with +. Since level is an int and hp is a float, you'll need to wrap them in str() first. Something like: "Player: " + player + " | Level: " + str(level) + ...