Based on this notebook with very minor changes.
First and foremost, the IPython Notebook is an interactive environment for writing and running Python code.
Run a code cell using Shift-Enter
or pressing the "Play" button in the toolbar above:
a = 10
print(a)
Code is run in a separate process called the IPython Kernel. The Kernel can be interrupted or restarted. Try running the following cell and then hit the "Stop" button in the toolbar above.
import time
time.sleep(10)
If the Kernel dies you will be prompted to restart it. Here we call the low-level system libc.time routine with the wrong argument via ctypes to segfault the Python interpreter:
import sys
from ctypes import CDLL
# This will crash a Linux or Mac system; equivalent calls can be made on Windows
dll = 'dylib' if sys.platform == 'darwin' else 'so.6'
libc = CDLL("libc.%s" % dll)
libc.time(-1) # BOOM!!
Here are two system aliases:
pwd
ls
Any command line program can be run using !
with string interpolation from Python variables:
message = 'The IPython notebook is great!'
# note: the echo command does not run on Windows, it's a unix command.
!echo $message
Tab completion works:
import numpy
numpy.random.
Tab completion after (
brings up a tooltip with the docstring:
numpy.random.rand(
Adding ?
opens the docstring in the pager below:
magic?
Exceptions are formatted nicely:
x = 1
y = 4
z = y/(1-x)
There are a number of ways of getting external code into code cells.
Pasting code with >>>
prompts works as expected:
>>> the_world_is_flat = 1
>>> if the_world_is_flat:
... print("Be careful not to fall off!")
The %load
magic lets you load code from URLs or local files:
%load?
%matplotlib inline
%load http://matplotlib.sourceforge.net/mpl_examples/pylab_examples/integral_demo.py
Using the %%file
magic, we can directly create a file
%%file helloworld.py
print("Hello World")
and can see the file on the file system:
!ls -l helloworld.py
and execute the file using the python interpreter:
!python helloworld.py
For example, if \(x=\alpha\) then \(x^2 = \alpha^2\). Furthermore \[ \int\limits_a^b f(x) \mathrm{d} x = \Gamma.\]
https://github.com/ipython/ipython/tree/master/examples/notebooks#a-collection-of-notebooks-for-using-ipython-effectively