错误Person() takes no arguments
时间: 2023-12-25 12:06:20 浏览: 35
这个错误通常出现在类的实例化时,例如:
```python
class Person:
def __init__(self, name):
self.name = name
person = Person()
```
这里,`Person()`需要一个参数`name`,但是我们没有给它,所以会抛出`TypeError: __init__() missing 1 required positional argument: 'name'`。要解决这个错误,我们需要给`Person()`传递一个`name`参数,例如:
```python
person = Person("Alice")
```
相关问题
Solution() takes no arguments
The error message "Solution() takes no arguments" indicates that you are trying to call a method or function without providing the necessary arguments.
For example, if you have defined a function called "hello" that takes a name as an argument, like this:
```
def hello(name):
print("Hello, " + name)
```
You would need to call the function with a name argument, like this:
```
hello("Alice")
```
If you call the function without any arguments, like this:
```
hello()
```
You will get the "TypeError: hello() takes exactly 1 argument (0 given)" error message, because the function expects one argument (the name), but you didn't provide any.
To fix the "Solution() takes no arguments" error, you need to make sure that you are calling the method with the correct number and type of arguments. You may need to check the method's documentation or the code where it is defined to see what arguments it expects.
Bar() takes no arguments
The error message "Bar() takes no arguments" means that you are trying to call a function named "Bar" with one or more arguments, but the function definition does not accept any arguments.
For example:
```
def Bar():
print("Hello, World!")
Bar("John") # This will raise the error "Bar() takes no arguments"
```
To fix this error, you need to either remove the arguments from the function call, or modify the function definition to accept the arguments.
For example:
```
def Bar(name):
print("Hello, " + name + "!")
Bar("John") # This will print "Hello, John!"
```
相关推荐
![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)
![](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)
![](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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)