0

Can someone please explain the difference between tuple and list?

15th Jan 2018, 8:00 PM
BathrobeOverlord69
BathrobeOverlord69 - avatar
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! ;)
15th Jan 2018, 8:13 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
0
Thank you both!
16th Jan 2018, 12:47 PM
BathrobeOverlord69
BathrobeOverlord69 - avatar