+ 3
When tuple is preferred over list
As tuples are immutable, they are inflexible. So, can you show some examples, where tuples are desirable
2 Respuestas
+ 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.
+ 4
You can create a list of days the week. days_week=(monday, ..., ...)