Tutorial Brief

Coding basic python in IPython Notebook interactive development environment.

Finding Help:

Basic Help with Coding


In [1]:
import sys
import io

In [2]:
io?

In [3]:
io??

Reference


In [4]:
# IPython Quick Refence
%quickref

In [5]:
# Python Refence
help()


Welcome to Python 2.7!  This is the online help utility.

If this is your first time using Python, you should definitely check out
the tutorial on the Internet at http://docs.python.org/2.7/tutorial/.

Enter the name of any module, keyword, or topic to get help on writing
Python programs and using Python modules.  To quit this help utility and
return to the interpreter, just type "quit".

To get a list of available modules, keywords, or topics, type "modules",
"keywords", or "topics".  Each module also comes with a one-line summary
of what it does; to list the modules whose summaries contain a given word
such as "spam", type "modules spam".

help> 

You are now leaving help and returning to the Python interpreter.
If you want to ask for help on a particular object directly from the
interpreter, you can type "help(object)".  Executing "help('string')"
has the same effect as typing a particular string at the help> prompt.

In [ ]:
%pdoc io.FileIO

In [7]:
%pdef io.OpenWrapper


No definition header found for io.OpenWrapper

In [8]:
%psource io

In [9]:
%pfile io

Tab completion


In [10]:
# Browse an object with tab
sys


Out[10]:
<module 'sys' (built-in)>

In [ ]:
# Shift-tab to get more information about a method
open()

More Magic


In [12]:
# Listing all magic
%lsmagic


Out[12]:
Available line magics:
%alias  %alias_magic  %autocall  %automagic  %autosave  %bookmark  %cat  %cd  %clear  %colors  %config  %connect_info  %cp  %debug  %dhist  %dirs  %doctest_mode  %ed  %edit  %env  %gui  %hist  %history  %install_default_config  %install_ext  %install_profiles  %killbgscripts  %ldir  %less  %lf  %lk  %ll  %load  %load_ext  %loadpy  %logoff  %logon  %logstart  %logstate  %logstop  %ls  %lsmagic  %lx  %macro  %magic  %man  %matplotlib  %mkdir  %more  %mv  %notebook  %page  %pastebin  %pdb  %pdef  %pdoc  %pfile  %pinfo  %pinfo2  %popd  %pprint  %precision  %profile  %prun  %psearch  %psource  %pushd  %pwd  %pycat  %pylab  %qtconsole  %quickref  %recall  %rehashx  %reload_ext  %rep  %rerun  %reset  %reset_selective  %rm  %rmdir  %run  %save  %sc  %store  %sx  %system  %tb  %time  %timeit  %unalias  %unload_ext  %who  %who_ls  %whos  %xdel  %xmode

Available cell magics:
%%!  %%HTML  %%SVG  %%bash  %%capture  %%debug  %%file  %%html  %%javascript  %%latex  %%perl  %%prun  %%pypy  %%python  %%python2  %%python3  %%ruby  %%script  %%sh  %%svg  %%sx  %%system  %%time  %%timeit  %%writefile

Automagic is ON, % prefix IS NOT needed for line magics.

In [13]:
# Measuring Performance
%timeit range(1000)
%timeit xrange(1000)


100000 loops, best of 3: 13.9 µs per loop
10000000 loops, best of 3: 198 ns per loop

In [14]:
%%timeit
# Measuring Block Performance

for x in range(1000):
    y=x+1


10000 loops, best of 3: 65.1 µs per loop

In [15]:
%%timeit
# Measuring Block Performance

for x in xrange(1000):
    y=x+1


1000 loops, best of 3: 488 µs per loop

In [16]:
# Reset (Delete) all variables
%reset


Once deleted, variables cannot be recovered. Proceed (y/[n])? n
Nothing done.

In [17]:
%%bash
echo $PATH


/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin

Output and Input

You have access to all code inside you code cell and the out put from them in two lists: In and Out.


In [18]:
3+5


Out[18]:
8

In [21]:
In[18]


Out[21]:
u'3+5'

In [22]:
Out[18]


Out[22]:
8

In [23]:
_ + 3


Out[23]:
11

In [24]:
_ - 4


Out[24]:
7