IPython#

This short tutorial is a very brief exploration of the essential features of IPython and Jupyter Notebooks. It is mainly based on content from Python for Data Analysis by Wes McKinney.

You can run any file as a Python program inside the environment of your IPython session using the %run command. Suppose you had the following simple script stored in ipython_script_test.py:

def f(x, y, z):
    return (x + y) / z

a = 5
b = 6
c = 7.5

result = f(a, b, c)

You can execute this by passing the filename to %run:

%run ipython_script_test.py

In the Jupyter notebook, you may also use the related %load magic function, which imports a script into a code cell:

Magic commands#

  • IPython’s special commands (which are not built into Python itself) are known as “magic” commands

  • These are designed to facilitate common tasks

  • A magic command is any command prefixed by the percent symbol %.

%pwd
'/home/runner/work/python-basics/python-basics/docs'
foo = %pwd

foo
'/home/runner/work/python-basics/python-basics/docs'
  • Type %quickref to view all magic commands

%quickref