如何在 python REPL 中编写多行代码? :
aircraftdeMacBook-Pro:~ ldl$ python
Python 2.7.10 (default, Jul 30 2016, 19:40:32)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
例如示例:
i = 0
while i < 10:
i += 1
print i
在终端中,我不知道如何在 python shell 中换行:
我测试了 Control
+ Enter
、 Shift
+ Enter
和 Command
+ Enter
,它们都错了:
>>> while i < 10:
... print i
File "<stdin>", line 2
print i
^
IndentationError: expected an indented block
原文由 aircraft 发布,翻译遵循 CC BY-SA 4.0 许可协议
只需复制代码并将其粘贴到终端中,然后按回车键。如果您这样做,此代码将完美运行: