float() argument must be a string or a number, not 'method'
时间: 2023-05-29 16:02:14 浏览: 127
This error message is raised when you try to pass a method (a function that belongs to a class) as an argument to the `float()` function in Python. The `float()` function is used to convert a string or a number to a floating point number.
For example, let's say you have a method `my_method()` in a class `MyClass`:
```
class MyClass:
def my_method(self):
return 10.5
```
And you try to pass this method as an argument to the `float()` function:
```
obj = MyClass()
result = float(obj.my_method)
```
This will raise the error message:
```
TypeError: float() argument must be a string or a number, not 'method'
```
To fix this error, you need to call the method and pass the result to the `float()` function:
```
obj = MyClass()
result = float(obj.my_method())
```
Now, `result` will be a floating point number.
阅读全文
相关推荐


















