When running IPython if you evaluate a semicolon you get a return value of the empty string, as shown below. Why? My theory is that it's IPython stripping out the line terminator in the statement but that still doesn't explain why it returns a 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's features.
%quickref -> Quick reference.
help -> Python's 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, should have been clearer: this doesn't work in the standard Python shell, only in IPython.
IPython has special handling for semicolons at the start of the line. For example:
In [1]: ;ord A # autocall -- calls function "ord" on string "A"
Out[1]: 65
It looks like if it can't parse a function name, you get buggy 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 with IPython 2.4.1 running Python 3.5.2.)
So I wouldn't try to interpret it as "stripping out a line terminator" or trying to relate it back to Python syntax.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With