What is a tuple useful for?

后端 未结 11 776
天涯浪人
天涯浪人 2021-02-01 12:45

I am learning Python for a class now, and we just covered tuples as one of the data types. I read the Wikipedia page on it, but, I could not figure out where such a data type wo

11条回答
  •  粉色の甜心
    2021-02-01 13:24

    Tuples and lists have the same uses in general. Immutable data types in general have many benefits, mostly about concurrency issues.

    So, when you have lists that are not volatile in nature and you need to guarantee that no consumer is altering it, you may use a tuple.

    Typical examples are fixed data in an application like company divisions, categories, etc. If this data change, typically a single producer rebuilts the tuple.

提交回复
热议问题