What is a tuple useful for?

后端 未结 11 771
天涯浪人
天涯浪人 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:15

    Tuples are used in :

    1. places where you want your sequence of elements to be immutable
    2. in tuple assignments
    a,b=1,2
    
    1. in variable length arguments
    def add(*arg) #arg is a tuple
        return sum(arg)
    

提交回复
热议问题