0

Can someone please explain the difference between tuple and list?

15th Jan 2018, 8:00 PM
BathrobeOverlord69
BathrobeOverlord69 - avatar
3 ответов
+ 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
+ 2
The difference between lists and tuples is that a list is mutable and tuples are immutable. The main difference between mutable and immutable is memory usage when you are trying to append an item. When you create a variable, some fixed memory is assigned to the variable. If it is a list, more memory is assigned than actually used. Reference: stackoverflow.com -> https://www.google.com/url?sa=t&source=web&rct=j&url=https://stackoverflow.com/q/626759&ved=0ahUKEwj06dnr4trYAhVR3mMKHbCmBcsQFgggMAE&usg=AOvVaw2NfTzT2hS9XJ7xtNF3Ml0f
15th Jan 2018, 8:10 PM
Dread
Dread - avatar
0
Thank you both!
16th Jan 2018, 12:47 PM
BathrobeOverlord69
BathrobeOverlord69 - avatar