📘 Day 2: Lists, Tuples, Sets & Dictionaries in Python


🔹 1. Lists

fruits = ["apple", "banana", "cherry"]
fruits.append("orange")
fruits[1] = "mango"
print(fruits)  # ['apple', 'mango', 'cherry', 'orange']
✅ Common Methods: append(), insert(), remove(), pop(), sort(), reverse()

🔹 2. Tuples

coordinates = (10, 20)
print(coordinates[0])  # 10
# coordinates[0] = 30  ❌ Error!
✅ Used when values should not change, e.g., GPS coordinates.

🔹 3. Sets

unique_numbers = {1, 2, 3, 2, 4}
print(unique_numbers)  # {1, 2, 3, 4}
Common Uses: Removing duplicates, set operations (union, intersection, difference)

🔹 4. Dictionaries

person = {"name": "Alice", "age": 25}
person["city"] = "New York"
print(person["name"])  # Alice
✅ Access with keys, not indexes.

📌 Summary Table

Data TypeOrderedMutableAllows DuplicatesSyntax
List[]
Tuple()
Set{}
Dictionary✅*❌ (keys){key:val}

💡 Interview Tips


🔍 Practice Questions