how to add value to a tuple?

后端 未结 8 1698
别那么骄傲
别那么骄傲 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:27

    As other people have answered, tuples in python are immutable and the only way to 'modify' one is to create a new one with the appended elements included.

    But the best solution is a list. When whatever function or method that requires a tuple needs to be called, create a tuple by using tuple(list).

提交回复
热议问题