When to use tuples vs lists? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 1

When to use tuples vs lists?

16th May 2016, 11:09 PM
Nelson Stevenson Sprovera
Nelson Stevenson Sprovera - avatar
4 Antworten
+ 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
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