๐น int โ Whole numbers
age = 25
Real-life analogy
Counting cricket runs: 1, 2, 4, 6.
ML use-case
Storing epochs, batch size, etc.
๐น float โ Decimal numbers
learning_rate = 0.001
Real-life analogy
Measuring petrol in liters: 1.5 L.
ML use-case
Model metrics: accuracy = 92.57, loss = 0.024
๐น bool โ True/False
is_training = True
Real-life analogy
Switch ON/OFF.
ML use-case
Checking if model is in training or evaluation mode.
๐น str โ Text
name = "Ali"
Real-life analogy
Your WhatsApp message.
ML use-case
Text datasets for NLP models.
๐ 2. List โ Ordered, changeable (mutable), allows duplicates
fruits = ["apple", "banana", "mango"]
โ Properties
- Ordered
- Mutable (you can change elements)
- Allows duplicates
โ Real-life analogy
A shopping list โ you can rearrange, add, remove items.
โ Operations
fruits.append("orange") fruits[1] = "grapes" print(fruits)
โ ML use-case
Storing multiple predictions:
preds = [0.1, 0.4, 0.8, 0.3]
๐ 3. Tuple โ Ordered, NOT changeable (immutable), allows duplicates
point = (3, 5)
โ Properties
- Ordered
- Immutable
- Fast
- Allows duplicates
โ Real-life analogy
Your Aadhaar details โ once fixed, cannot modify easily.
โ ML use-case
Coordinates in feature space (x, y), image pixel shape:
shape = (224, 224, 3)
โ Why use tuple?
- Faster than list
- Safe from accidental modification
๐ 4. Set โ Unordered, unique elements only, no duplicates
unique_ids = {101, 102, 103}
โ Properties
- Unordered
- Only unique items
- Super fast for membership test (
in)
โ Real-life analogy
Your Instagram followers list automatically removes duplicates.
โ ML use-case
Getting unique labels/class names:
labels = set(["cat", "dog", "cat", "mouse"])
Output:
{'cat', 'dog', 'mouse'}
๐ 5. Dictionary (dict) โ Keyโvalue pairs
student = {"name": "Ali", "age": 22}
โ Properties
- Keyโvalue mapping
- Fast lookup
- Ordered (Python 3.7+)
โ Real-life analogy
A contact list:
- “Maa” โ 9876543210
- “Papa” โ 1234567890
โ Operations
student["age"] = 23 student["city"] = "Nashik"
โ ML use-case
Hyperparameters:
config = { "learning_rate": 0.001, "batch_size": 32, "optimizer": "adam" }
๐ฅ Side-by-side summary table
| Type | Ordered | Mutable | Allows duplicates | Example |
|---|---|---|---|---|
| list | โ | โ | โ | [1, 2, 3] |
| tuple | โ | โ | โ | (1, 2, 3) |
| set | โ | โ | โ | {1, 2, 3} |
| dict | โ (keys) | โ | Keys unique | {"a":1} |
๐ง Mini Exercises (Try these)
Q1
Create a list of 5 movies and replace the 3rd one.
Q2
Convert this list to a set:
nums = [1, 2, 2, 3, 4, 4, 5]
Q3
Create a dictionary for a model config with keys:
- model_name
- epochs
- lr
- optimizer
Q4
Why would you use a tuple instead of a list?
Source: DEV Community.

Leave a Reply