array() takes from 1 to 2 positional but 3 were given
时间: 2023-10-31 12:04:43 浏览: 126
This error message is indicating that the `array()` function was called with more arguments than it can accept.
The `array()` function in Python is used to create an array, which is a collection of values of the same data type. It can take one or two positional arguments, depending on the use case.
If only one argument is provided, it should be an iterable object (such as a list or tuple) containing the values for the array. For example:
```
my_array = array([1, 2, 3, 4, 5])
```
If two arguments are provided, the first should be a string indicating the data type of the values in the array, and the second should be an iterable object containing the values. For example:
```
my_array = array('i', [1, 2, 3, 4, 5])
```
The error message suggests that three arguments were provided to the `array()` function, which is not allowed. To fix this error, you should check the code where the `array()` function is called and make sure that it is being called with the correct number of arguments.
阅读全文