+ 3

When tuple is preferred over list

As tuples are immutable, they are inflexible. So, can you show some examples, where tuples are desirable

21st Sep 2016, 3:10 AM
Rohit Kumar
2 Réponses
+ 7
Tuples are faster than. If you're defining a constant set of values and all need to do with it is iterate through it, then use of a tuple is better instead of a list. It makes the code safer if the data “write-protect” that does not need to be changed. Using a tuple instead of a list is like having an implied assert statement that this data is constant, and that special thought (and a specific function) is required to override that. Like geometrical coordinates, which always have three value.
21st Sep 2016, 5:39 AM
Md Mizanur Rahman
Md Mizanur Rahman - avatar
+ 4
You can create a list of days the week. days_week=(monday, ..., ...)
1st Oct 2016, 5:15 AM
Paolo Di Paolo
Paolo Di Paolo - avatar