问题:
为什么编辑器中的这段代码会编译
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
答案 0 :(得分:-1)
>>> name = "Sophie"
>>> for i in name:
... <try press tab in here>print(f"***{i}***")
你错过了那个缩进。