IndentationError: expected an indented block after class definition on line 4
时间: 2023-10-12 17:21:12 浏览: 85
This error typically occurs in Python when there is a missing indentation after a class definition. When defining a class and its methods, it is important to indent the code that belongs to the class. Here is an example of correct indentation:
```
class MyClass:
def __init__(self):
self.my_var = "Hello World"
def my_method(self):
print(self.my_var)
```
In this example, the `__init__` method and `my_method` method are indented under the class definition. If there is no indentation, Python will raise an `IndentationError`:
```
class MyClass:
def __init__(self):
self.my_var = "Hello World"
```
This will result in the following error message:
```
IndentationError: expected an indented block
```
阅读全文