我在编辑器中尝试了这段代码:
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
出了什么问题,如何解决?
>>> name = "Sophie"
>>> for i in name:
... <try press tab in here>print(f"***{i}***")
你错过了那个缩进。