2025-06-20
Theme: Data Types and Structures in Python
This week we’ll explore how Python stores and organizes data.
You’ll learn:
The building blocks: strings, integer, float, booleans
How to use lists, tuples, dictionaries, and sets
Real-world examples in data science
Every variable in Python has a type that determines:
What kind of data it holds
What operations you can perform
Knowing the type helps you avoid errors and write better code.
Common types in Python:
| Type | Example | Purpose |
|---|---|---|
int |
10 |
Whole numbers |
float |
3.14 |
Decimal numbers |
str |
"Hello" |
Text data |
bool |
True/False |
Logic/conditions |
We use these constantly in Python scripts and data analysis.
Python has 4 main ways to group multiple items:
| Structure | Mutable | Ordered | Use case |
|---|---|---|---|
list |
✅ | ✅ | Store items in order |
tuple |
❌ | ✅ | Store fixed sequences |
dict |
✅ | ✅ | Key-value pairs (like JSON) |
set |
✅ | ❌ | Unique items only |
Each has its own strengths!
You can:
Add: fruits.append("orange")
Remove: fruits.remove("apple")
Loop: for f in fruits: print(f)
Great for datasets and sequences!
Tuples are like lists but immutable (unchangeable):
We use tuples for:
Fixed values (e.g. coordinates, settings)
Keys in dictionaries
You can’t append() or remove() from a tuple.
Access with keys:
Ideal for:
JSON-like data
Mapping IDs to values
Storing structured info
We use sets to:
Remove duplicates
Compare groups: A & B, A | B
Check membership quickly
Where you’ll see data structures:
CSV data → Lists of dictionaries
JSON APIs → Dictionaries and nested lists
Feature columns → Lists, arrays, sets
Unique categories → Sets
Mastering types helps you clean, explore, and analyze data confidently.