TypeError: __init__() got an unexpected keyword argument 'size'
时间: 2023-10-01 22:06:00 浏览: 110
This error occurs when you try to pass an unexpected keyword argument to a function or method.
For example, if you have a class called `Square` that has an `__init__` method that takes in a `width` and `height` argument, but you try to pass a `size` argument instead:
```
class Square:
def __init__(self, width, height):
self.width = width
self.height = height
square = Square(size=10)
```
You will get the `TypeError: __init__() got an unexpected keyword argument 'size'` error because `__init__` does not expect a `size` argument.
To fix this error, you should either remove the unexpected keyword argument or modify the function or method to accept it. In the above example, you could modify the `__init__` method to accept a `size` argument:
```
class Square:
def __init__(self, size):
self.width = size
self.height = size
square = Square(size=10)
```
阅读全文