len() takes exactly one argument (2 given)
时间: 2023-11-23 14:05:55 浏览: 280
This error message means that the function len() was called with two arguments, but it expects only one argument.
For example, if you have the following code:
```
string1 = "hello"
string2 = "world"
length = len(string1, string2)
```
The len() function is being called with both string1 and string2 as arguments. However, len() only takes one argument, so the code will produce a TypeError with the message "len() takes exactly one argument (2 given)".
To fix this error, you need to call len() with only one argument, like this:
```
string1 = "hello"
length = len(string1)
```
相关问题
TypeError: len() takes exactly one argument (2 given)
This error message is indicating that the `len()` function was given two arguments, but it expected only one.
Here's an example of how this error might occur:
```
my_list = [1, 2, 3]
print(len(my_list, 2))
```
In this code, we're trying to call the `len()` function with two arguments: `my_list` and `2`. However, `len()` expects only one argument (the object whose length we want to find), so it raises a `TypeError`.
To fix this error, we need to pass only one argument to `len()`, like this:
```
my_list = [1, 2, 3]
print(len(my_list))
```
Now, `len()` is receiving only one argument (`my_list`), so it knows what to do and returns the correct length of the list (which is 3, in this case).
TypeError: len() takes exactly one argument (2 given)这啥错误
这个错误通常发生在调用 len() 函数时传递了多个参数的情况下。len() 函数只接受一个参数,该参数可以是一个序列、一个映射或一个集合,用于返回该序列、映射或集合中元素的数量。如果传递多个参数,会引发 TypeError 错误。
可能的原因是在调用 len() 函数时,将多个参数传递给它了,例如:
```
len(arg1, arg2)
```
应该将其修改为:
```
len(arg1)
```
或者需要将多个参数合并成一个序列、映射或集合,然后再将其传递给 len() 函数。
阅读全文