Variables, Data Types, and Operators¶
Learn how Python stores information, labels what kind of value it is, and combines values into useful results.
This is the first detailed notebook in the fundamentals sequence. It turns the high-level map from the section overview into concrete syntax you will use in almost every Python program.

Python programs become useful as soon as they can remember values, understand what kind of values they hold, and combine or compare those values with operators.
That is why variables, data types, and operators appear everywhere: revenue calculations, discount checks, customer labels, performance metrics, and model thresholds all depend on them.
Why This Matters¶
Variables store measures like sales, costs, or conversion rates. Operators help calculate totals, margins, and growth.
Model code stores features, thresholds, labels, and scores in variables before any algorithm can act on them.
Clear variable names and correct value types make code easier to debug and far easier to trust.
Concept Map¶
Core Explanation¶
A variable is a name attached to a value. The data type tells Python how that value should behave. Operators then let you transform, compare, or update the value.
| Idea | Example | Why it matters |
|---|---|---|
| Variable | sales = 25000 | stores a value for reuse |
| String | company = "Bright Retail" | stores text labels |
| Integer | customers = 120 | stores whole numbers |
| Float | tax_rate = 0.18 | stores decimal values |
| Boolean | is_profitable = True | stores yes/no style logic |
| Operator | revenue = units * price | creates new results from values |
Reading the output
intmeans a whole numberfloatmeans a decimal numberstrmeans textboolmeans a value such asTrueorFalse
Operators in Action¶
The same values can be combined in different ways depending on the operator you use.
| Operator family | Examples | Typical use |
|---|---|---|
| Arithmetic | +, -, *, / | totals, averages, differences, revenue |
| Comparison | >, <, ==, != | checking targets or thresholds |
| Assignment | =, +=, -= | storing or updating a value |
Worked Example¶
Suppose a business sells 180 units of a product at a price of 45 each and wants to know whether revenue beats a weekly target of 7000.
Why this matters
This example combines four fundamentals at once:
storing values in variables
choosing numeric data types
using arithmetic operators to compute a result
using a comparison operator to ask a business question
Quick Quiz¶
Which value is most likely a string in Python?¶
sales = 32000
costs = 21000
profit = sales - costs
print("Initial profit:", profit)
refund = 1500
profit = profit - refund
print("Profit after refund:", profit)Initial profit: 11000
Profit after refund: 9500
price = 12.5
quantity = 40
revenue = price * quantity
target = 450
print("Revenue:", revenue)
print("Revenue meets target:", revenue >= target)Revenue: 500.0
Revenue meets target: True
Exercises¶
Create variables for product name, price, and quantity, then print a readable summary.
Store a boolean value that represents whether a customer is active.
Compute total cost using multiplication and compare two values using
>or<.
Quick Summary
variables store values
data types describe the kind of value
operators help compute and compare results
these ideas appear in almost every Python program
The next notebook builds on this by teaching Python how to make decisions using conditions.
8. Interactive Code¶
Expected output
RetailCo
42
0.18Expected output
str
bool
float