+ 1

When to use tuples vs lists?

16th May 2016, 11:09 PM
Nelson Stevenson Sprovera
Nelson Stevenson Sprovera - avatar
4 odpowiedzi
+ 8
Tuples are fixed size in nature whereas lists are dynamic. In other words, a tuple is immutable whereas a list is mutable. You can't add elements to a tuple. Tuples have no append or extend method. You can't remove elements from a tuple. Tuples have no remove or pop method. You can find elements in a tuple, since this doesn’t change the tuple. You can also use the in operator to check if an element exists in the tuple.
24th May 2016, 11:49 AM
James Flanders
+ 2
Well, StackOverflow gives a pretty good explanation http://stackoverflow.com/a/1708538
22nd Jun 2016, 4:46 AM
Mykola Zekter
Mykola Zekter - avatar
+ 1
I think that tuples can help in case you want to make lists as dictionary keys. List cant be keys, but you can transform them in tuples and use as keys
3rd Jul 2016, 8:32 AM
Алексей Клочков
Алексей Клочков - avatar
0
tuples are static , u must use them when setting the resolution of your game that's made with pygame. lists are dynamic and can be used to make an inventory in an mmorpg ( just an example)
25th Jun 2016, 6:44 PM
Renken Dz
Renken Dz - avatar