+ 19
Advantage of using tuples?
18 Answers
+ 23
some of tuples advantages:😐😙
1.The objects in tuples are more safe when compared to list or dictionary and hence they are commenly made into use
2.tuples are compiled faster when compared to list
+ 16
Immutability means they can be used as Dictionary keys, too, as long as they don't contain mutable objects.
That might be useful for a dictionary of places, for example, when you store locations with an x and y coordinate tuple as a key, but the name of the store or home or whatever at that location (the value) might change.
+ 15
Tuples are faster than lists, but they cannot be changed.
Hope I helped
+ 10
There is a syntactical advantage too.
Tuples are often used as a return value of a function. Sometimes it is very convenient.
https://code.sololearn.com/cxG6BKjCakav/#py
Or in-place swap:
a, b = b, a
+ 10
You can return two or more values using tuple
+ 7
Tuples are immutable, easier and faster to process
+ 6
Some of the advantages are:
>>> A tuple can't be change. That is it is immutable
>>> These are faster when processed as compared to lists and sets
>>> Hence these are protected too
+ 6
From a data analytic perspective, tuple immutability is really nice when the series of values are themselves key to the element's identity - as @Talley mentions, they may be used as dictionary keys because of this, but it's also a useful type when the contained sequence is a cryptokey, list of primes, etc. Being able to return multiple values at once while keeping them immutable can be useful for avoiding errors due to misreference or even malicious code injections that seek to change values.
+ 5
immutable faster
+ 4
I'd refrain from using 'but' immutable, as being immutable can be a good thing. The tuple is faster to use (a large tuple is faster than a large list), and is also immutable, so the data can't be changed by accident, which may cause part of your program to fail.
+ 4
In my experience, tuples are generally used where order and position is meaningful and consistant. For example, in creating a data structure for a choose your own adventure game, I chose to use tuples instead of lists because the position in the tuple was meaningful.
+ 4
Tuples are not only faster than lists,but also difficult to change.This means you won't change the values by mistake.
Hope this helped ~
+ 4
Mostly everything is said I would just like to add that tuples being imutable can act as constants ( similar to final variables in Java)
Certain applications do require some global constant variables (although I have never implemented a big application is python) but I guess tuples could be used for it
+ 3
thanks to all.
+ 3
you can't change/ reassign them, and you can permanently store data
+ 2
The way tuples are stored in memory is more efficient than the allocation for a list or dict.