+ 1

Lists vs Tuples

I know what both are. lists are ordered and changeable and and allow duplicates and tuples are ordered and immutable and allow duplicates. I just cant figure which one to use to do something. They both have the same definitions. LITERALLY. if you look up what lists/tuples python in google it will give you the same defintion. Im asking when to use which?

5th Jun 2023, 8:23 PM
Junior
Junior - avatar
5 odpowiedzi
+ 6
The main difference is that you cannot change the tuple once you've created it. So if you want to add, change or remove data, you better go for a list than for a tuple.
5th Jun 2023, 8:33 PM
Lisa
Lisa - avatar
+ 1
Lisa Thanks, I thought i was doing it wrong but i got it now 👌
5th Jun 2023, 8:35 PM
Junior
Junior - avatar
+ 1
Although what Lisa said about tuples is correct, there are still ways in which you can edit tuples
5th Jun 2023, 8:39 PM
Lamron
Lamron - avatar
+ 1
Lamron You would have to create a new tuple/ overwrite the previous one. Or something more hacky. 😉
5th Jun 2023, 8:43 PM
Lisa
Lisa - avatar
+ 1
Lisa yes, which is a pain... Inefficient
5th Jun 2023, 8:45 PM
Lamron
Lamron - avatar