+ 18

What are the differences between tuple and list ??i am really confused BTW the two because they both look like the same,And ....

28th May 2019, 1:13 AM
SωAti
SωAti - avatar
7 Answers
+ 17
Tuples are immutable(constant) but list are mutable . Tuples are faster than lists. If you're defining a constant set of values and all you're ever going to do with it is iterate through it, use a tuple instead of a list
29th May 2019, 10:20 AM
Vijay(v-star🌟)
Vijay(v-star🌟) - avatar
+ 9
If you're wondering "why would I need immutable data structures?", it is because they are hashable. That means they can be used as keys to a dictionary. It also guarantees that none of the data will change, so you can be sure that they are "safe" and no other part of your program can mess with it.
28th May 2019, 1:23 AM
Eduardo Petry
Eduardo Petry - avatar
+ 9
The data which can be rewritable that is mutable so as list but tuple is immutable because indexing in tuple cannot support the relocation of data from one place to other when it is stored .Another diff is list is written in square bracket s whereas tuple is written in circular brackets.
28th May 2019, 1:26 AM
SωAti
SωAti - avatar
+ 4
Yes, kind of. You can still retrieve data contained inside a tuple, though (example below). You just cannot modify it internally. Think of it as some kind of read-only memory. my_tuple = (0, True, "potato", False, 7) second_element = my_tuple[1] print("The second element of the tuple is: " + str(second_element))
28th May 2019, 1:32 AM
Eduardo Petry
Eduardo Petry - avatar
+ 2
List are mutable means we can change the value of list whereas tuple are immutable means we cannot change the value of tuple.
29th May 2019, 7:48 PM
Ajay
Ajay - avatar
+ 2
1.tuple uses () and list [] 2.tuple is immutable & list is mutable.
3rd Jun 2019, 3:16 PM
B!P!N R@j
B!P!N R@j - avatar