- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我认为这是完全正确的。
if False:
print(1)
print(2)
但是,它在 Python REPL 中给我一个无效的语法错误。
这是为什么?
在 Python 3.6.5 (x64)、Windows 10 RS4 上
最佳答案
正如 user2357112 所指出的,这种行为在 https://docs.python.org/3/tutorial/introduction.html#first-steps-towards-programming 中有解释。 ,
The body of the loop is indented: indentation is Python’s way of grouping statements. At the interactive prompt, you have to type a tab or space(s) for each indented line. In practice you will prepare more complicated input for Python with a text editor; all decent text editors have an auto-indent facility. When a compound statement is entered interactively, it must be followed by a blank line to indicate completion (since the parser cannot guess when you have typed the last line). Note that each line within a basic block must be indented by the same amount.
关于python - 为什么我在 IF 语句后立即在 Python REPL 中收到无效语法错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50901923/
我是一名优秀的程序员,十分优秀!