01What is the difference between a list and a tuple in Python?Beginner
A list is mutable: you can add, remove or change its elements after it is created. A tuple is immutable: once it is defined, its values cannot change.
Use a list when the data changes while the program runs. Use a tuple for fixed values such as coordinates, database rows or configuration, where an accidental change would be a bug. Tuples can also be dictionary keys, because they are hashable.
# List - mutable
cities = ["Delhi", "Mumbai", "Bangalore"]
cities.append("Chennai")
# Tuple - immutable
coordinates = (28.61, 77.20)
# coordinates[0] = 30 # TypeError: 'tuple' object does not support item assignment