list.append() takes exactly one argument (2 given)
时间: 2023-02-07 22:37:01 浏览: 177
这个错误消息的意思是,你在使用 `list.append()` 方法时给了它两个参数,但是这个方法只能接受一个参数。这意味着你应该只给 `list.append()` 方法传递一个参数。例如,如果你想向列表中添加一个新元素,你应该这样写:
```
my_list = [1, 2, 3]
my_list.append(4) # correct
```
而不是这样:
```
my_list = [1, 2, 3]
my_list.append(4, 5) # wrong - gives "TypeError: append() takes exactly one argument (2 given)"
```
相关问题
TypeError: list.append() takes exactly one argument (2 given)
This error is raised when the `append()` method of a list is called with more than one argument. The `append()` method is used to add an element to the end of a list.
Example:
```
my_list = [1, 2, 3]
my_list.append(4, 5) # Raises TypeError: append() takes exactly one argument (2 given)
```
To fix this error, make sure that the `append()` method is called with only one argument.
Example:
```
my_list = [1, 2, 3]
my_list.append(4)
print(my_list) # Output: [1, 2, 3, 4]
```
TypeError: list.append() takes exactly one argument (3 given)
This error occurs when you try to pass more than one argument to the `append()` method of a list. The `append()` method only takes one argument, which is the item you want to add to the end of the list.
For example, if you have a list called `my_list` and you want to add the integers 1, 2, and 3 to the end of the list, you might try to do it like this:
```
my_list = []
my_list.append(1, 2, 3)
```
However, this will result in a `TypeError` because you are passing three arguments to the `append()` method instead of just one.
To fix this error, you need to call the `append()` method once for each item you want to add to the list:
```
my_list = []
my_list.append(1)
my_list.append(2)
my_list.append(3)
```
Now the integers 1, 2, and 3 will be added to the end of the `my_list` list, and you will not get a `TypeError`.
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![java](https://img-home.csdnimg.cn/images/20210720083646.png)