def change(tupleTest):
tupleTest[0] = 2
tupleTest = (1, 2, 3)
change(tupleTest)
print(tupleTest)
The above code explodes the problem error
the solution is actually easier to understand
Tuple is only readable, and does not support writing. Therefore, there is a problem with tuple assignment
Generally, if you want to do operations similar to arrays in C/C + +, you’d better use list
instead of the following code to avoid similar errors
def change(tupleTest):
tupleTest[0] = 2
tupleTest = [1, 2, 3]
change(tupleTest)
print(tupleTest)
Although this name is still very unreliable
a suggestion for beginners of Python is that the name of the code is very important. Python is typeless (the type is not displayed obviously…)
Similar Posts:
- Python TypeError: not all arguments converted during string formatting
- How to Solve Python TypeError: ‘list’ object is not callable
- AttributeError: ‘tuple’ object has no attribute ‘extend’
- Python: `if not x:` VS `if x is not None:` VS `if not x is None:`
- Go build cannot find package Error [How to Solve]
- [Solved] Tensorflow Error: ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type numpy.ndarray)
- ArrayList reported an error: Unsupported operationexception
- Python: __ new__ Method and the processing of typeerror: object() takes no parameters
- Python3.x Run Python2.x Codes syntax error: “Missing parentheses in call to ‘print’
- Error reporting and resolution of Python 3 using binascii method