+ 3
What are the advantages and disadvantages of using tuples instead of lists.
4 ответов
+ 14
It is a very good question.
One good thing about tuples is that they use less memory. Lists use more memory.
The downside is that tuples are immutable, so they can't be changed.
But the good thing about that is the fact that you can use tuples in a dictionary, as a key. While you can't do so with a list.
You as a programmer should choose them.
+ 3
Advantages of Tuples
* Allows you to output the whole tuple
* Allows you to output a specific element
* Allows you to combine
* Allows you find an item using the index function
* Allows you to calculat the length of your tuple
NOTE THAT A LIST HAS ALL THE ABOVE CHARACTERISTICS.
* Tuple uses less memory space
Disadvantages of Tuples
* You can't add an element but in a list you can
* You can't sort a tuple but in a list you can
* You can't delete an element but you can in a list
* You can't replace an element but you can in a list
+ 1
@Alireza How you can use tuples in a dictionary, as a key?
0
If you store tuple like as I did
tup=(1,2,3,4,5....n)
Then you can change the key to tuple by dict_keys= tup