[英]How do I fix indentation error when creating a class in Python?
Every time I try to create a class, it gives me the IndentationError
when I haven't even added indentations yet.每次我尝试创建一个 class 时,它都会在我还没有添加缩进时给我
IndentationError
。
I have tried restarting Jupyter and my PC and there is no luck.我试过重新启动 Jupyter 和我的电脑,但没有成功。 I have also tried using another notebook but still face the error.
我也尝试过使用另一个笔记本,但仍然遇到错误。
As the error shows, it is expecting an indented block after the class.如错误所示,它期望在 class 之后有一个缩进块。
So add a statement in there, example:因此,在其中添加一条语句,例如:
class Animal():
pass
You should understand the basics of classes in python for this.为此,您应该了解 python 中的类的基础知识。 It is working fine, the only thing is that your code is incomplete.
它工作正常,唯一的问题是您的代码不完整。 After you declare a class, it is simply expecting a class body.
在您声明 class 之后,它只是期待一个 class 主体。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.