IPython Getting Started
Launching IPython is as simple as typing its name on the command line. The shell starts in the current working directory, prints a banner with version information, and presents the In [1]: prompt. From there, every line you enter is real Python — plus the extra conveniences described in this chapter.
$ ipython
Python 3.11.7 | packaged by conda-forge
Type 'copyright', 'credits' or 'license' for more information
IPython 8.20.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]:
Exploring Objects
The question mark is your primary navigation tool. Appending ? to a name prints a summary: type, constructor signature, docstring, file, and class ancestors. Double question marks show the source code itself:
In [1]: import collections
In [2]: collections.Counter?
Init signature: collections.Counter(*args, **kwds)
Docstring: Dict subclass for counting hashable items.
In [3]: collections.Counter??
Tab Completion and Command Recall
Press Tab after a partial name and IPython completes variables, attributes, module members, and — in notebooks and recent releases — even keyword arguments of a function call. Once you have used a variable, later lines can reuse it without retyping:
In [4]: import statistics
In [5]: sample = [4, 8, 15, 16, 23, 42]
In [6]: round(statistics.mean(sample), 2)
Out[6]: 18
The up-arrow recalls previous lines one by one, and pressing Ctrl-R opens an incremental history search, exactly as in bash. History persists across sessions in the SQLite profile directory.
Getting Help
Magics are mini-commands that configure or extend the shell. %quickref prints a cheat sheet, %magic lists every magic in detail, and bare ? opens the introduction page:
In [7]: %quickref
IPython -- An enhanced Interactive Python
Quick reference ...
In [8]: %whos
Variable Type Data/Info
----------------------------
sample list [4, 8, 15, 16, 23, 42]
statistics module /.../statistics.py
Leaving the Shell
Type exit or press Ctrl-D to quit. If the prompt asks for confirmation, y exits cleanly; passing --no-confirm-logo-style flags or setting the prompt skips it permanently.
Summary
Start the shell with ipython, explore objects with ? and ??, complete names with Tab, recall history with the arrows or Ctrl-R, and learn the magics via %quickref, %magic, and %whos.