ipython notebook has a bunch of cool gui features, namely that you can display things like charts and diagrams in the browser. But this guide is dealing with ipython in the terminal:
(venv) hack $ ipython
Python 3.13.2 (main, Feb 6 2025, 22:53:04) [Clang 13.0.0 (clang-1300.0.29.30)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.32.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]:
My traditional way to test if a prompt is accepting and evaluating input is simply to enter 3:
In [1]: 3
Out[1]: 3
You can access the input history with control+p
for previous and control+n
for next (or arrow keys).
History is persistent across sessions, so you can keep hitting the up arrow past the “first” input to access previous sessions’ input.
You can access the last result using _
:
In [2]: _
Out[2]: 3
In fact you can access all inputs and outputs using the In
and Out
objects:
In [5]: Out[1]
Out[5]: 3
You can access documentation for a function or object by putting a ?
after it:
In [8]: print?
Signature: print(*args, sep=' ', end='\n', file=None, flush=False)
Docstring:
Prints the values to a stream, or to sys.stdout by default.
...
Modules are objects too, you can see their documentation like so:
In [20]: import socket
In [21]: socket?
In this case it’ll bring up the pager since it’s more than a screen’s worth of information. Use space
to page forward, b
to page backwards, /
to search, and q
to exit out of the pager.
Finally, you can use 2 question marks (??
) to see the source of an object:
In [22]: socket??
This has even more text so it opens up the pager as well.
Note that some objects, especially builtins like print
and input
, do not show their source with the double question mark, likely because they are implemented in c and loaded from their compiled form.
When you’re ready to exit the repl, type exit
or hit control+d
.
I use control+d because it’s easier to type, however it gives another prompt:
Do you really want to exit ([y]/n)?
You can just hit control+d
again, but fortunately this can be disabled through configuration.
Create a profile (from the command line, not the ipython prompt):
(venv) hack $ ipython profile create
[ProfileCreate] Generating default config file: PosixPath('/Users/razzi/.ipython/profile_default/ipython_config.py')
Edit that and look for the commented out line with c.TerminalInteractiveShell.confirm_exit
. Uncomment it and change it to False
:
c.TerminalInteractiveShell.confirm_exit = False