inputipythonmultiline

How can I create a multi line input in IPython?


I am reading the book Python Data Science Handbook by Jake VanderPlas. In the first chapter a multi line input in IPython is illustrated:

multiLineInput

Can anybody please tell me how to do that? I know how to write a block before executing it in Jupyter Notebook, but in the IPython shell I don't know how to do it.


Solution

  • Ctrl+o

    If you type Ctrl+o, you should be able to add additional lines to the input to run them simultaneously.

    If that doesn't work, as a workaround, you can paste multiple lines after copying them from elsewhere, or you can press enter on a line with a semicolon or unclosed parentheses. IPython will automatically give you another line to finish your statement rather than running and instantly hitting a syntax error.

    Depending on the environment where you are running IPython, you might also want to try Ctrl+Enter or Shift+Enter.