为什么分号在IPython中返回一个空字符串?

Ben*_*gar 6 python ipython

在运行IPython时,如果计算分号,则会得到空字符串的返回值,如下所示.为什么?我的理论是,它是IPython在声明中剥离行终止符,但仍然无法解释为什么它返回一个字符串.

$ ipython
Python 2.7.12 (default, Oct 11 2016, 05:24:00)
Type "copyright", "credits" or "license" for more information.

IPython 5.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: ;
Out[1]: ''
Run Code Online (Sandbox Code Playgroud)

这也适用于Python 3的IPython.

编辑:对不起,应该更清楚:这在标准的Python shell中不起作用,仅在IPython中.

K. *_*uhr 5

IPython在该行的开头对分号进行了特殊处理。例如:

In [1]: ;ord A   # autocall -- calls function "ord" on string "A"
Out[1]: 65
Run Code Online (Sandbox Code Playgroud)

看起来如果它无法解析函数名称,则会出现错误行为:

In [4]: ;;;
Out[4]: ';;'

In [5]: ;?huh
Out[5]: '?huh'

In [6]: ;?huh?
Object `huh` not found.

In [7]: ;?huh
Out[7]: '?huh;?huh'

In [8]: 
Run Code Online (Sandbox Code Playgroud)

(以上是与运行Python 3.5.2的IPython 2.4.1一起使用的。)

因此,我不会尝试将其解释为“剥离行终止符”或尝试将其与Python语法相关联。