getting-started-ipython/script.rst
author Anoop Jacob Thomas<anoop@fossee.in>
Tue, 26 Oct 2010 11:01:31 +0530
changeset 347 7ac0296d1cf6
parent 275 146a6bf5c30b
child 378 fa4c9b11452b
permissions -rw-r--r--
Reviewed getting started with ipython script.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     1
.. Objectives
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     2
.. ----------
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
     3
246
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     4
.. At the end of this tutorial, you will be able to 
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     5
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     6
.. 1. invoke the ``ipython`` interpreter. 
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     7
.. #. quit the ``ipython`` interpreter. 
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     8
.. #. navigate in the history of ``ipython``. 
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
     9
.. #. use tab-completion. 
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    10
.. #. look-up documentation of functions. 
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    11
.. #. interrupt incomplete or incorrect commands.
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    12
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    13
.. Prerequisites
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    14
.. -------------
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    15
246
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    16
.. should have ``ipython`` and ``pylab`` installed. 
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    17
     
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    18
.. Author              : Puneeth 
347
7ac0296d1cf6 Reviewed getting started with ipython script.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 275
diff changeset
    19
   Internal Reviewer   : Anoop Jacob Thomas<anoop@fossee.in>
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    20
   External Reviewer   :
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    21
   Checklist OK?       : <put date stamp here, if OK> [2010-10-05]
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    22
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    23
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    24
Script
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    25
------
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    26
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    27
{{{ Show the slide containing title }}}
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    28
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    29
Hello Friends and Welcome to the tutorial on getting started with
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    30
``ipython``. 
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    31
246
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    32
{{{ Show slide with outline }}}
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    33
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    34
This tutorial will cover the basic usage of the ``ipython``
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    35
interpreter. The following topics would be covered.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    36
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    37
IPython is an enhanced Python interpreter that provides features like
246
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    38
tabcompletion, easier access to help and lot of other functionality
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    39
which are not available in the vanilla Python interpreter.
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    40
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    41
First let us see how to invoke the ``ipython`` interpreter.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    42
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    43
We type
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    44
::
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    45
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    46
  ipython
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    47
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    48
at the terminal prompt to invoke the ipython interpreter.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    49
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    50
We get a prompt with ``In [1]:`` after getting some information about
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    51
the version of Python installed and some help commands.   
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    52
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    53
If you get an error saying something like ``ipython is not
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    54
installed``, refer to the tutorial on how to install the packages
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    55
required for this course.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    56
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    57
Now, to quit the ipython interpreter, type Ctrl-D.  You are prompted
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    58
asking if you really want to exit, type y to say yes and quit ipython.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    59
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    60
Start ipython again, as you did before.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    61
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    62
The prompt that you have says ``In [1]``. ``In`` stands for input and the
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    63
ipython interpreter is ready to accept input from you.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    64
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    65
Now let us see, how we can type some commands into the interpreter.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    66
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    67
Start with the simplest thing, addition.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    68
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    69
Let's type 
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    70
::
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    71
  1+2 
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    72
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    73
at the prompt. IPython promptly gives back the output as 3.  Notice
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    74
that the output is displayed with an ``Out[1]`` indication.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    75
347
7ac0296d1cf6 Reviewed getting started with ipython script.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 275
diff changeset
    76
.. #[[Anoop: I think we can illustrate In [] and Out[] in slides]]
7ac0296d1cf6 Reviewed getting started with ipython script.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 275
diff changeset
    77
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    78
Let's try out few other mathematical operations.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    79
::
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    80
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    81
  5 - 3
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    82
  7 - 4
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    83
  6 * 5
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    84
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    85
Now let's ``print 1+2``. Instead of typing the whole thing, we make
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    86
use of the fact that IPython remembers the history of the commands
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    87
that you have already used. We use the up arrow key to go back the
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    88
command ``1+2``. We then use the left-arrow key to navigate to the
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    89
beginning of the line and add the word ``print`` and a space. Then hit
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    90
enter and observe that the interpreter prints out the value as 3,
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    91
without the Out[] indication.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    92
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    93
Now, let's change the previous command ``print 1+2`` to ``print
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    94
10*2``.  We use the up arrow again to navigate to the previous command
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    95
and use the left arrow key to move the cursor on to the + symbol and
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    96
then use the delete key to remove it and type 0 and * to change the
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    97
expression to the required one.  We hit enter to see the output of
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    98
``print``. 
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    99
347
7ac0296d1cf6 Reviewed getting started with ipython script.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 275
diff changeset
   100
.. #[[Anoop: We could create a slide with heading Tab Completion and
7ac0296d1cf6 Reviewed getting started with ipython script.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 275
diff changeset
   101
   give the question as an exercise, basically I feel more slides
7ac0296d1cf6 Reviewed getting started with ipython script.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 275
diff changeset
   102
   should be used]]
7ac0296d1cf6 Reviewed getting started with ipython script.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 275
diff changeset
   103
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   104
Now, let's say we want to use the function ``round``. We type ``ro``
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   105
at the prompt and hit the tab key. As you can see, the IPython
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   106
completes the command. This feature is called the tab-completion.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   107
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   108
Now, we remove all the characters and just type ``r`` and then hit
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   109
tab. IPython does not complete the command since there are many
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   110
possibilities. It just lists out all the possible completions.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   111
246
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   112
Following is an exercise that you must do. 
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   113
347
7ac0296d1cf6 Reviewed getting started with ipython script.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 275
diff changeset
   114
.. #[[Anoop: Include slides for exercises]]
7ac0296d1cf6 Reviewed getting started with ipython script.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 275
diff changeset
   115
275
146a6bf5c30b Slides for gatting started with ipython
Puneeth Chaganti <punchagan@fossee.in>
parents: 246
diff changeset
   116
%%1%% Type ``ab`` and hit tab to see what happens. Next, just type
246
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   117
``a`` and hit tab to see what happens.
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   118
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   119
Please, pause the video here. Do the exercise and then continue. 
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   120
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   121
``ab`` tab completes to ``abs`` and ``a<tab>`` gives us a list of all
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   122
the commands starting with a. 
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   123
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   124
Now, let's see what these functions are used for.  We will use the
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   125
help features of ipython to find this out.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   126
347
7ac0296d1cf6 Reviewed getting started with ipython script.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 275
diff changeset
   127
.. #[[Anoop: Another slide which says about ? mark and round? etc, as
7ac0296d1cf6 Reviewed getting started with ipython script.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 275
diff changeset
   128
   few people cannot just follow by listening (like me) :)]]
7ac0296d1cf6 Reviewed getting started with ipython script.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 275
diff changeset
   129
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   130
To get the help of any function, we first type the function, ``abs``
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   131
in our case and then add a ? at the end and hit enter.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   132
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   133
As the documentation says, ``abs`` accepts a number as an input and
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   134
returns it's absolute value.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   135
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   136
We say, 
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   137
::
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   138
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   139
  abs(-19)
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   140
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   141
  abs(19)
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   142
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   143
We get 19, as expected, in both the cases.  
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   144
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   145
Does it work for decimals (or floats)?  Let's try typing abs(-10.5)
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   146
and we do get back 10.5.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   147
246
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   148
Following is an exercise that you must do. 
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   149
347
7ac0296d1cf6 Reviewed getting started with ipython script.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 275
diff changeset
   150
.. #[[Anoop: add slide]]
7ac0296d1cf6 Reviewed getting started with ipython script.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 275
diff changeset
   151
246
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   152
%%2%% Look-up the documentation of ``round`` and see how to use it.
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   153
246
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   154
Please, pause the video here. Do the exercise and then continue. 
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   155
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   156
::
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   157
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   158
 round?
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   159
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   160
If you notice, there are extra square brackets around the ``ndigits``.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   161
This means that ``ndigits`` is optional and 0 is the default value.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   162
Optional parameters are shown in square brackets anywhere in Python
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   163
documentation.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   164
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   165
The function ``round``, rounds a number to a given precision.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   166
246
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   167
Following are exercises that you must do. 
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   168
347
7ac0296d1cf6 Reviewed getting started with ipython script.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 275
diff changeset
   169
.. #[[Anoop: add slide]]
7ac0296d1cf6 Reviewed getting started with ipython script.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 275
diff changeset
   170
246
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   171
%%3%% Check the output of::
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   172
246
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   173
  round(2.48)
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   174
  round(2.48, 1)
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   175
  round(2.48, 2)
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   176
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   177
  round(2.484)
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   178
  round(2.484, 1)
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   179
  round(2.484, 2)
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   180
246
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   181
Please, pause the video here. Do the exercises and then continue. 
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   182
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   183
We get 2.0, 2.5 and 2.48, which are what we expect. 
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   184
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   185
Let's now see how to correct typing errors that we make when typing at
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   186
the terminal. As already shown, if we haven't hit the enter key
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   187
already, we could navigate using the arrow keys and make deletions
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   188
using delete or backspace key and correct the errors. 
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   189
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   190
Let's now type round(2.484 and hit enter, without closing the
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   191
parenthesis. We get a prompt with dots.  This prompt is the
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   192
continuation prompt of ``ipython``.  It appears, the previous line is
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   193
incomplete in some way.  We now complete the command by typing, the
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   194
closing parenthesis and hitting enter.  We get the expected output of
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   195
2.5. 
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   196
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   197
In other instances, if we commit a typing error with a longer and more
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   198
complex expression and end up with the continuation prompt, we can
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   199
type Ctrl-C to interrupt the command and get back the ``ipython`` input
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   200
prompt.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   201
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   202
Following is an exercise that you must do. 
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   203
347
7ac0296d1cf6 Reviewed getting started with ipython script.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 275
diff changeset
   204
.. #[[Anoop: add slide]]
7ac0296d1cf6 Reviewed getting started with ipython script.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 275
diff changeset
   205
246
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   206
%%4%% Try typing round(2.484, and hit enter. and then cancel the
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   207
command using Ctrl-C. Then, type the command, round(2.484, 2) and
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   208
resume the video.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   209
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   210
Please, pause the video here. Do the exercises and then continue. 
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   211
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   212
::
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   213
  
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   214
  round(2.484 
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   215
  ^C
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   216
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   217
  round(2.484, 2)
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   218
  
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   219
This brings us to the end of the tutorial on getting started with
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   220
``ipython``.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   221
347
7ac0296d1cf6 Reviewed getting started with ipython script.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 275
diff changeset
   222
.. #[[Anoop: add slides for interrupts, navigating history, I feel
7ac0296d1cf6 Reviewed getting started with ipython script.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 275
diff changeset
   223
    even a single point will also do]]
7ac0296d1cf6 Reviewed getting started with ipython script.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 275
diff changeset
   224
275
146a6bf5c30b Slides for gatting started with ipython
Puneeth Chaganti <punchagan@fossee.in>
parents: 246
diff changeset
   225
In this tutorial we have learnt, how to
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   226
{{{ show the outline/summary slide. }}}
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   227
275
146a6bf5c30b Slides for gatting started with ipython
Puneeth Chaganti <punchagan@fossee.in>
parents: 246
diff changeset
   228
  1. invoke the ``ipython`` interpreter. 
146a6bf5c30b Slides for gatting started with ipython
Puneeth Chaganti <punchagan@fossee.in>
parents: 246
diff changeset
   229
  #. quit the ``ipython`` interpreter. 
146a6bf5c30b Slides for gatting started with ipython
Puneeth Chaganti <punchagan@fossee.in>
parents: 246
diff changeset
   230
  #. navigate in the history of ``ipython``. 
146a6bf5c30b Slides for gatting started with ipython
Puneeth Chaganti <punchagan@fossee.in>
parents: 246
diff changeset
   231
  #. use tab-completion. 
146a6bf5c30b Slides for gatting started with ipython
Puneeth Chaganti <punchagan@fossee.in>
parents: 246
diff changeset
   232
  #. look-up documentation of functions. 
146a6bf5c30b Slides for gatting started with ipython
Puneeth Chaganti <punchagan@fossee.in>
parents: 246
diff changeset
   233
  #. interrupt incomplete or incorrect commands.
146a6bf5c30b Slides for gatting started with ipython
Puneeth Chaganti <punchagan@fossee.in>
parents: 246
diff changeset
   234
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   235
{{{ Show the "sponsored by FOSSEE" slide }}}
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   236
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   237
This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   238
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   239
Hope you have enjoyed and found it useful.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   240
Thank you!