I have a tuple called values
which contains the following:
JavaScript
x
2
1
('275', '54000', '0.0', '5000.0', '0.0')
2
I want to change the first value (i.e., 275
) in this tuple but I understand that tuples are immutable so values[0] = 200
will not work. How can I achieve this?
Advertisement
Answer
It’s possible via:
JavaScript
1
5
1
t = ('275', '54000', '0.0', '5000.0', '0.0')
2
lst = list(t)
3
lst[0] = '300'
4
t = tuple(lst)
5
But if you’re going to need to change things, you probably are better off keeping it as a list