how to add value to a tuple?

Tuples are immutable and not supposed to be changed – that is what the list type is for.

However, you can replace each tuple using originalTuple + (newElement,), thus creating a new tuple. For example:

t = (1,2,3)
t = t + (1,)
print(t)
(1,2,3,1)

But I’d rather suggest to go with lists from the beginning, because they are faster for inserting items.

And another hint: Do not overwrite the built-in name list in your program, rather call the variable l or some other name. If you overwrite the built-in name, you can’t use it anymore in the current scope.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)