Get Started with IPython
Learn the basics of interactive Python computing
Starting IPython
Once installed, start IPython by typing:
$ ipython
IPython 8.18.1 -- An enhanced Interactive Python
Type 'copyright', 'credits' or 'license' for more information
IPython -- Productive Interactive Computing
In [1]: You're now in the IPython shell! Type Python code and press Enter to execute it.
Basic Python Code
IPython works like standard Python, but with enhanced features:
In [1]: x = 10
In [2]: y = 20
In [3]: x + y
Out[3]: 30
In [4]: name = "IPython"
In [5]: f"Hello, {name}"
Out[5]: 'Hello, IPython!' Tab Completion
Press Tab to complete code. This works for:
- Object attributes:
import numpy; numpy.[TAB] - Function parameters:
open([TAB] - Filenames:
open('/path/to/[TAB]
Try typing something and pressing Tab - IPython will suggest completions!
Explore Objects with ? and ??
View help and source code instantly:
function_name? Show documentation and signature
function_name?? Show source code
In [1]: import numpy
In [2]: numpy.array?
Type: type
String form: <class 'numpy.ndarray'>
Docstring:
ndarray(shape, dtype=float, buffer=None, offset=0,
strides=None, order=None) Magic Commands
IPython special commands starting with % or %%:
%timeit sum(range(100)) Time code execution to find bottlenecks
%run my_script.py Execute a Python script in IPython
%ls Run shell commands
Shell Integration
Execute shell commands directly with !:
In [1]: !ls
In [2]: files = !find . -name "*.py"
In [3]: len(files)
Out[3]: 42 Capture command output directly into Python variables!
Next Steps
- Explore the Features page for more advanced capabilities
- Read the official documentation
- Try interactive notebooks with Jupyter
- Get help on the Community page