TypeError: len() takes exactly one argument (2 given)
时间: 2024-05-15 15:15:27 浏览: 170
Python 'takes exactly 1 argument (2 given)' Python error
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).
阅读全文