how to add value to a tuple?

后端 未结 8 1699
别那么骄傲
别那么骄傲 2020-12-08 03:43

I\'m working on a script where I have a list of tuples like (\'1\',\'2\',\'3\',\'4\'). e.g.:

list = [(\'1\',\'2\',\'3\',\'4\'),
        (\'2\',\         


        
8条回答
  •  春和景丽
    2020-12-08 04:09

    I was going through some details related to tuple and list, and what I understood is:

    • Tuples are Heterogeneous collection data type
    • Tuple has Fixed length (per tuple type)
    • Tuple are Always finite

    So for appending new item to a tuple, need to cast it to list, and do append() operation on it, then again cast it back to tuple.

    But personally what I felt about the Question is, if Tuples are supposed to be finite, fixed length items and if we are using those data types in our application logics then there should not be a scenario to appending new items OR updating an item value in it. So instead of list of tuples it should be list of list itself, Am I right on this?

提交回复
热议问题