1.What is the difference between a list and a tuple?
Show hint
One of them can be changed after it is created.
Show solution
- A list (
[1, 2, 3]) is mutable: you can add, remove and change items. - A tuple (
(1, 2, 3)) is immutable: once created, it cannot be changed.
Use tuples for fixed groups of values (coordinates, a database row, multiple return values). Because they are immutable, tuples can be used as dictionary keys and set members; lists cannot.