ipython is an interactive version of the python interpreter. It provides a number of extras which are helpful when writing code.
ipython code is almost always
python code, and the differences are generally only important when editing a code in a live (interactive) environment.
jupyter notebook is a fine example of an interactive environment - you are changing the code as it runs and checking answers as you go. Because you may have a lot of half-completed results in an interactive script, you probably want to make as few mistakes as you can. This is the purpose of
ipython provides access to the help / documentation system, provides tab completion of variable and function names, allows you see see what methods live inside a module …
## Try the autocomplete ... it works on functions that are in scope
# it also works on variables
long_but_helpful_variable_name = 1
It works on modules to list the available methods and variables. Take the
math module, for example:
math.isinf # Try completion on this
# try math.isinf() and hit shift-tab while the cursor is between the parentheses
# you should see the same help pop up.
It works on functions that take special arguments and tells you what you need to supply.
Try this and try tabbing in the parenthesis when you use this function yourself:
string.capwords("the quality of mercy is not strained")
It also provides special operations that allow you to drill down into the underlying shell / filesystem (but these are not standard python code any more).
# execute simple unix shell commands
Another way to do this is to use the cell magic functionality to direct the notebook to change the cell to something different (here everything in the cell is interpreted as a unix shell )
I don’t advise using this too often as the code becomes more difficult to convert to python.
%is a one-line magic function that can go anywhere in the cell.
%%is a cell-wide function
%magic # to see EVERYTHING in the magic system !
Useful magic functions:
%matplotlib inlinemakes plots appear in the notebook and not an external window
%run FILEruns the contents of the file in place of the given cell
%%timeittimes how long the cell takes to run
You can also run ipython in the terminal / shell on this machine. You will see that some of the interactivity still works in a text environment but not all of the pop up help is as helpful as in the notebooks.