🟩 1. List ([])
Mutable, ordered collection of items.
✅ Create
fruits = ['apple', 'banana', 'cherry']
🔧 Access & Modify
fruits[0] # 'apple'
fruits[1] = 'kiwi'
➕ Add/Remove
fruits.append('orange') # Add at end
fruits.insert(1, 'grape') # Insert at index
fruits.remove('banana') # Remove item
fruits.pop() # Remove last item
🔁 Loop
for fruit in fruits:
print(fruit)
---
🟦 2. Tuple (())
Immutable, ordered collection of items.
✅ Create
point = (10, 20)
🔧 Access (Not Modify)
point[0] # 10
point[0] = 15 ❌ Error: Tuples are immutable
🔁 Loop
for val in point:
print(val)
🔄 Conversion
list(point) # Convert to list
tuple(['a', 'b']) # Convert to tuple
---
🟨 3. Dictionary ({})
Mutable, unordered (as of Python 3.6+, it maintains order), key-value pairs.
✅ Create
person = {'name': 'Alice', 'age': 30}
🔧 Access/Modify
person['name'] # 'Alice'
person['age'] = 31 # Modify
➕ Add/Remove
person['city'] = 'NYC' # Add
del person['age'] # Remove
🔁 Loop
for key, value in person.items():
print(key, value)
🧪 Check Key
'name' in person # True