The code below prompt error
def change(tupleTest):
tupleTest[0] = 2
tupleTest = (1, 2, 3)
change(tupleTest)
print(tupleTest)
TypeError: tuple object does not support item assignment
The solution is actually easier to understand. That is:
Generally, if you want to do operations similar to arrays in C/C++
, it is best to use list.
Change the above example to the following code will not explode similar errors
def change(tupleTest):
tupleTest[0] = 2
tupleTest = [1, 2, 3]
change(tupleTest)
print(tupleTest)