交互式 shell 与编辑器

时间:2021-07-21 12:10:29

标签: python shell editor

问题:

为什么编辑器中的这段代码会编译

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

1 个答案:

答案 0 :(得分:-1)

>>> name = "Sophie"
>>> for i in name:
... <try press tab in here>print(f"***{i}***")

你错过了那个缩进。

相关问题