0
Can someone please explain the difference between tuple and list?
3 Antworten
+ 6
Similarities:
1. Both are collections of elements of same or different types.
2. Subscriptable.
3. Iterable.
4. Sliceable.
5. Can be created by comprehension expressions.
Differences:
1. Lists are mutable (its elements can be changed), while tuples are not.
2. Tuples can thus be dictionary keys, while lists may not.
3. Lists can also be expanded or shrunk (add or remove elements), while tuples can't.
So when:
a = list(x for x in range(5))
b = tuple(for x in range(5))
a[0] = 88 👍
b[0] = 88 👎
Hope this helps! ;)
0
Thank you both!