Solution() takes no arguments
时间: 2023-09-28 22:07:29 浏览: 107
The error "Solution() takes no arguments" typically occurs when you try to pass an argument to a class that does not accept any arguments in its constructor.
Here's an example code that could generate this error:
```
class Solution:
def __init__(self):
self.score = 0
def update_score(self, new_score):
self.score = new_score
solution = Solution(10) # this will raise "Solution() takes no arguments" error
```
In the above code, the `Solution` class does not accept any arguments in its constructor, yet we are trying to pass an argument of `10` when we create an instance of the class. To fix this error, we need to remove the argument:
```
class Solution:
def __init__(self):
self.score = 0
def update_score(self, new_score):
self.score = new_score
solution = Solution() # no error
```
Now, we can create an instance of the `Solution` class without any arguments.
阅读全文