getting-started-ipython/script.rst
author bhanu
Sun, 07 Nov 2010 00:04:06 +0530
changeset 384 525ae0d74e47
parent 378 fa4c9b11452b
permissions -rw-r--r--
checked the language for `loading data from files` and check list done by Anand.
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>
384
525ae0d74e47 checked the language for `loading data from files`
bhanu
parents: 378
diff changeset
    20
   Language Review     : Bhanukiran 
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    21
   External Reviewer   :
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    22
   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
    23
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    24
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    25
Script
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
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    28
{{{ Show the slide containing title }}}
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    29
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    30
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
    31
``ipython``. 
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    32
246
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
    33
{{{ Show slide with outline }}}
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    34
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    35
This tutorial will cover the basic usage of the ``ipython``
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    36
interpreter. The following topics would be covered.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    37
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    38
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
    39
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
    40
which are not available in the vanilla Python interpreter.
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    41
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    42
First let us see how to invoke the ``ipython`` interpreter.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    43
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    44
We type
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
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    47
  ipython
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    48
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    49
at the terminal prompt to invoke the ipython interpreter.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    50
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    51
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
    52
the version of Python installed and some help commands.   
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    53
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    54
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
    55
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
    56
required for this course.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    57
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    58
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
    59
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
    60
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    61
Start ipython again, as you did before.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    62
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    63
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
    64
ipython interpreter is ready to accept input from you.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    65
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    66
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
    67
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    68
Start with the simplest thing, addition.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    69
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    70
Let's type 
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    71
::
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    72
  1+2 
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    73
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    74
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
    75
that the output is displayed with an ``Out[1]`` indication.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    76
347
7ac0296d1cf6 Reviewed getting started with ipython script.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 275
diff changeset
    77
.. #[[Anoop: I think we can illustrate In [] and Out[] in slides]]
378
fa4c9b11452b Changes to getting started with ipython based on review.
Puneeth Chaganti <punchagan@fossee.in>
parents: 347
diff changeset
    78
.. #[[Puneeth: I think we can do that on the terminal?]]
347
7ac0296d1cf6 Reviewed getting started with ipython script.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 275
diff changeset
    79
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    80
Let's try out few other mathematical operations.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    81
::
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    82
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    83
  5 - 3
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    84
  7 - 4
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    85
  6 * 5
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    86
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    87
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
    88
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
    89
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
    90
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
    91
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
    92
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
    93
without the Out[] indication.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    94
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
    95
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
    96
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
    97
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
    98
then use the delete key to remove it and type 0 and * to change the
384
525ae0d74e47 checked the language for `loading data from files`
bhanu
parents: 378
diff changeset
    99
expression as required.  We hit enter to see the output of
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   100
``print``. 
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   101
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   102
Now, let's say we want to use the function ``round``. We type ``ro``
384
525ae0d74e47 checked the language for `loading data from files`
bhanu
parents: 378
diff changeset
   103
at the prompt and hit the tab key. As you can see, IPython
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   104
completes the command. This feature is called the tab-completion.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   105
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   106
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
   107
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
   108
possibilities. It just lists out all the possible completions.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   109
246
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   110
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
   111
275
146a6bf5c30b Slides for gatting started with ipython
Puneeth Chaganti <punchagan@fossee.in>
parents: 246
diff changeset
   112
%%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
   113
``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
   114
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   115
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
   116
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   117
``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
   118
the commands starting with a. 
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   119
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   120
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
   121
help features of ipython to find this out.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   122
347
7ac0296d1cf6 Reviewed getting started with ipython script.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 275
diff changeset
   123
.. #[[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
   124
   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
   125
378
fa4c9b11452b Changes to getting started with ipython based on review.
Puneeth Chaganti <punchagan@fossee.in>
parents: 347
diff changeset
   126
.. #[Punch: These things are shown on the terminal.  I feel we don't
fa4c9b11452b Changes to getting started with ipython based on review.
Puneeth Chaganti <punchagan@fossee.in>
parents: 347
diff changeset
   127
.. need slide, here I guess.]
fa4c9b11452b Changes to getting started with ipython based on review.
Puneeth Chaganti <punchagan@fossee.in>
parents: 347
diff changeset
   128
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   129
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
   130
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
   131
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   132
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
   133
returns it's absolute value.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   134
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   135
We say, 
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   136
::
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
  abs(-19)
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   139
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   140
  abs(19)
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   141
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   142
We get 19, as expected, in both the cases.  
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   143
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   144
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
   145
and we do get back 10.5.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   146
246
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   147
Following is an exercise that you must do. 
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   148
246
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   149
%%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
   150
246
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   151
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
   152
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   153
::
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   154
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   155
 round?
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
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
   158
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
   159
Optional parameters are shown in square brackets anywhere in Python
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   160
documentation.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   161
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   162
The function ``round``, rounds a number to a given precision.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   163
246
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   164
Following are exercises that you must do. 
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   165
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   166
%%3%% Check the output of::
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   167
246
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   168
  round(2.48)
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   169
  round(2.48, 1)
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   170
  round(2.48, 2)
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   171
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   172
  round(2.484)
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   173
  round(2.484, 1)
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   174
  round(2.484, 2)
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   175
246
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   176
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
   177
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   178
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
   179
384
525ae0d74e47 checked the language for `loading data from files`
bhanu
parents: 378
diff changeset
   180
Let's now see how to correct typing errors that we make while typing at
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   181
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
   182
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
   183
using delete or backspace key and correct the errors. 
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 type round(2.484 and hit enter, without closing the
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   186
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
   187
continuation prompt of ``ipython``.  It appears, the previous line is
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   188
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
   189
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
   190
2.5. 
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   191
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   192
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
   193
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
   194
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
   195
prompt.
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
Following is an exercise that you must do. 
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   198
246
95e7682e9d43 Cleaned up getting started with ipython LO.
Puneeth Chaganti <punchagan@fossee.in>
parents: 217
diff changeset
   199
%%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
   200
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
   201
resume the video.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   202
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   203
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
   204
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   205
::
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   206
  
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   207
  round(2.484 
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   208
  ^C
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
  round(2.484, 2)
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
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
   213
``ipython``.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   214
347
7ac0296d1cf6 Reviewed getting started with ipython script.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 275
diff changeset
   215
.. #[[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
   216
    even a single point will also do]]
7ac0296d1cf6 Reviewed getting started with ipython script.
Anoop Jacob Thomas<anoop@fossee.in>
parents: 275
diff changeset
   217
378
fa4c9b11452b Changes to getting started with ipython based on review.
Puneeth Chaganti <punchagan@fossee.in>
parents: 347
diff changeset
   218
.. #[Puneeth: I don't feel these things cannot be shown on a slide.]
fa4c9b11452b Changes to getting started with ipython based on review.
Puneeth Chaganti <punchagan@fossee.in>
parents: 347
diff changeset
   219
275
146a6bf5c30b Slides for gatting started with ipython
Puneeth Chaganti <punchagan@fossee.in>
parents: 246
diff changeset
   220
In this tutorial we have learnt, how to
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   221
{{{ show the outline/summary slide. }}}
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   222
275
146a6bf5c30b Slides for gatting started with ipython
Puneeth Chaganti <punchagan@fossee.in>
parents: 246
diff changeset
   223
  1. invoke the ``ipython`` interpreter. 
146a6bf5c30b Slides for gatting started with ipython
Puneeth Chaganti <punchagan@fossee.in>
parents: 246
diff changeset
   224
  #. quit the ``ipython`` interpreter. 
146a6bf5c30b Slides for gatting started with ipython
Puneeth Chaganti <punchagan@fossee.in>
parents: 246
diff changeset
   225
  #. navigate in the history of ``ipython``. 
146a6bf5c30b Slides for gatting started with ipython
Puneeth Chaganti <punchagan@fossee.in>
parents: 246
diff changeset
   226
  #. use tab-completion. 
146a6bf5c30b Slides for gatting started with ipython
Puneeth Chaganti <punchagan@fossee.in>
parents: 246
diff changeset
   227
  #. look-up documentation of functions. 
146a6bf5c30b Slides for gatting started with ipython
Puneeth Chaganti <punchagan@fossee.in>
parents: 246
diff changeset
   228
  #. interrupt incomplete or incorrect commands.
146a6bf5c30b Slides for gatting started with ipython
Puneeth Chaganti <punchagan@fossee.in>
parents: 246
diff changeset
   229
217
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   230
{{{ Show the "sponsored by FOSSEE" slide }}}
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   231
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   232
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
   233
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   234
Hope you have enjoyed and found it useful.
b595f90016c5 Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff changeset
   235
Thank you!