I have tried to assign new data to existing tuple, and it does not work.and actually I want to add the a and b to get a sum, however only string can be iterated..
A=[('3', '4'), ('3', '11'), ('8', '10')]
print A
for a,b in A:
a,b = int(a), int(b)+int(a)
print A
results:
[(‘3’, ‘4’), (‘3′, ’11’), (‘8′, ’10’)]
[(‘3’, ‘4’), (‘3′, ’11’), (‘8′, ’10’)]
When you set
a, b = int(a), int(b)+int(a), you do not change the actual objectaandbcame from; you just bind new objects the variables a and b…You can create a new list B, and populate it: