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)
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.
Shift-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 = True
>>> 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.org/mpl_examples/statistics/histogram_demo_features.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.$$