Python 代码块 :session 模式下能否执行受空行影响

首先这个是錯的。Python 用的是 if ...: elif ... else: ... 句式。

if True:
    1
else:
2

因為

if True:
    1

是一個合法语句,第二段代码结果的 2 实际是 2 的返回值。

Python 3.6.4 (default, Jan 13 2018, 17:39:32) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> if True:
...     1 # if statement ends here
... 
1
>>> 2
2
>>> ^D

另外 interactive test 还是直接上 REPL 吧,Python 又不是 C 这種要编绎才能运行的。你看你这樣用就出了理解误差。