1. Definition and syntax
| Type | Syntax | Structure |
| List | [1, "apple", True] | Ordered and mutable |
| Tuple | (1, "apple", True) | Ordered and immutable |
| Dictionary | {"name": "Ali", "age": 30} | Key–value mapping |
2. Feature comparison
| Feature | List | Tuple | Dictionary |
| Mutability | ✅ Mutable | ❌ Immutable | ✅ Mutable |
| Access | By index (0, 1, ...) | By index | By unique key |
| Keeps order | ✅ Yes | ✅ Yes | ✅ Since Python 3.7 |
| Duplicates | ✅ Allowed | ✅ Allowed | Keys: ❌ / Values: ✅ allowed |
| Typical use | Dynamic collections | Fixed, grouped data | Mapping and fast lookup |
3. Access examples
# List
my_list = ["apple", "banana", "cherry"]
print(my_list[0]) # Output: 'apple'
# Tuple
my_tuple = ("apple", "banana", "cherry")
print(my_tuple[1]) # Output: 'banana'
# Dictionary
my_dict = {"fruit1": "apple", "fruit2": "banana"}
print(my_dict["fruit2"]) # Output: 'banana'
4. When to use which?
- Lists: when you have a flexible collection that needs items added or changed.
- Tuples: for grouping fixed data such as coordinates or program constants.
- Dictionaries: when you need a fast mapping between keys and values, such as user profiles or app settings.
Conclusion
Understanding the differences between lists, tuples and dictionaries leads to cleaner, faster and more maintainable Python code. Choosing the right data structure for each job pays off in real projects.
Written & researched by Dr. Shahin Siami