Why does a semicolon return an empty string in IPython?

When starting IPython, if you evaluate the semicolon, you get the return value of the empty string, as shown below. What for? My theory is that IPython removes the line terminator in the statement, but that still doesn't explain why it returns the string.

$ 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 features. %quickref -> Quick reference. help -> Python own help system. object? -> Details about 'object', use 'object??' for extra details. In [1]: ; Out[1]: '' 

This also works in IPython for Python 3.

Edit: Sorry, it must have been clearer: this does not work in the standard Python shell, only in IPython.

+5
source share
1 answer

IPython has special handling for semicolons at the beginning of a line. For instance:

 In [1]: ;ord A # autocall -- calls function "ord" on string "A" Out[1]: 65 

It looks like if it cannot parse the function name, you will get the wrong behavior:

 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]: 

(The above is a description of IPython 2.4.1 running Python 3.5.2.)

So I would not interpret it as "crowding out a string terminator" or trying to associate it with Python syntax.

+4
source

Source: https://habr.com/ru/post/1261802/


All Articles