+ 18
What are the differences between tuple and list ??i am really confused BTW the two because they both look like the same,And ....
6 odpowiedzi
+ 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
+ 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.
+ 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.
+ 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))
+ 2
List are mutable means we can change the value of list whereas tuple are immutable means we cannot change the value of tuple.
+ 2
1.tuple uses () and list []
2.tuple is immutable & list is mutable.