交互式 shell 与编辑器[重复]

问题描述 投票:0回答:1

我在编辑器中尝试了这段代码:

name = "Sophie"
for i in name:
  print(f"***{i}***")

给出这个结果

***S***
***o***
***p***
***h***
***i***
***e***

但是交互式 shell 中的相同条目会出现错误:

>>> name = "Sophie"
>>> for i in name:
... print(f"***{i}***")
  File "<stdin>", line 2
    print(f"***{i}***")
    ^
IndentationError: expected an indented block

出了什么问题,如何解决?

python shell editor
1个回答
-1
投票
>>> name = "Sophie"
>>> for i in name:
... <try press tab in here>print(f"***{i}***")

你错过了那个缩进。

© www.soinside.com 2019 - 2024. All rights reserved.