Advantage of using tuples? | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
29th Nov 2017, 5:36 AM
Vishnu DxB
Vishnu DxB - avatar
16 Respuestas
+ 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
29th Nov 2017, 6:14 AM
VISHNU P.S
VISHNU P.S - avatar
+ 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.
30th Nov 2017, 4:48 AM
Talley Berry
Talley Berry - avatar
+ 15
Tuples are faster than lists, but they cannot be changed. Hope I helped
29th Nov 2017, 7:12 AM
Justine Ogaraku
Justine Ogaraku - avatar
+ 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
29th Nov 2017, 10:36 AM
Sergej Schelle
Sergej Schelle - avatar
+ 10
You can return two or more values using tuple
29th Nov 2017, 7:18 PM
Melki Ct
Melki Ct - avatar
+ 7
Tuples are immutable, easier and faster to process
29th Nov 2017, 9:27 AM
Jeremiah Vivian
Jeremiah Vivian - avatar
+ 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
30th Nov 2017, 8:43 AM
#RahulVerma
#RahulVerma - avatar
+ 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.
2nd Dec 2017, 9:42 PM
J.t. Lovelace
J.t. Lovelace - avatar
+ 5
immutable faster
29th Nov 2017, 2:32 PM
zlf
zlf - avatar
+ 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.
30th Nov 2017, 1:03 PM
LunarCoffee
LunarCoffee - avatar
+ 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.
3rd Dec 2017, 3:40 PM
sandeep Singh Yadav
sandeep Singh Yadav - avatar
+ 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 ~
5th Dec 2017, 2:14 AM
Leo
Leo  - avatar
+ 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
8th Dec 2017, 3:59 AM
surabhi
surabhi  - avatar
+ 3
thanks to all.
1st Dec 2017, 1:36 PM
Harsh Bhardwaj
Harsh Bhardwaj - avatar
+ 3
you can't change/ reassign them, and you can permanently store data
3rd Dec 2017, 9:28 AM
Okayouwin
Okayouwin - avatar
+ 2
The way tuples are stored in memory is more efficient than the allocation for a list or dict.
3rd Dec 2017, 2:20 AM
John Miller
John Miller - avatar