我哪里做错了?(我是初学者),我该如何正确?

  • 本文关键字:何正确 初学者 错了 python
  • 更新时间 :
  • 英文 :

>>> def f(x):
... return x**2
File "<stdin>", line 2
return x**2
^
IndentationError: expected an indented block

这里是:

>>> def f(x):
...     return x**2 
... 
>>> f(2) 
4

Python缩进

缩进是指代码行开头的空格。

在其他编程语言中,代码中的缩进用于仅可读性,Python中的缩进非常重要。

Python使用缩进来表示代码块。

有关缩进的更多信息,请查看本教程。

最新更新