summaryrefslogtreecommitdiff
path: root/getting_started_with_ipython/script.rst
diff options
context:
space:
mode:
Diffstat (limited to 'getting_started_with_ipython/script.rst')
-rw-r--r--getting_started_with_ipython/script.rst445
1 files changed, 323 insertions, 122 deletions
diff --git a/getting_started_with_ipython/script.rst b/getting_started_with_ipython/script.rst
index 703cccc..a3aacae 100644
--- a/getting_started_with_ipython/script.rst
+++ b/getting_started_with_ipython/script.rst
@@ -1,18 +1,18 @@
.. Objectives
.. ----------
-.. At the end of this tutorial, you will be able to
+.. At the end of this tutorial, you will be able to,
-.. 1. invoke the ``ipython`` interpreter.
+.. 1. invoke the ``ipython`` interpreter .
.. #. quit the ``ipython`` interpreter.
.. #. navigate in the history of ``ipython``.
-.. #. use tab-completion.
+.. #. use of tab-completion for writing ipython functions.
.. #. look-up documentation of functions.
.. #. interrupt incomplete or incorrect commands.
.. Prerequisites
.. -------------
-
+.. (it should be given in the first module)
.. should have ``ipython`` and ``pylab`` installed.
.. Author : Puneeth
@@ -25,211 +25,412 @@
Script
------
-{{{ Show the slide containing title }}}
+.. L1
+{{{ Show the first slide containing title, name of the production team along with the logo of MHRD }}}
-Hello Friends and Welcome to the tutorial on getting started with
-``ipython``.
+.. R1
-{{{ Show slide with outline }}}
+Hello Friends and Welcome to the tutorial on "getting started with
+``ipython``".
-This tutorial will cover the basic usage of the ``ipython``
-interpreter. The following topics would be covered.
+.. L2
-IPython is an enhanced Python interpreter that provides features like
-tabcompletion, easier access to help and lot of other functionality
-which are not available in the vanilla Python interpreter.
+{{{ Show slide with objectives }}}
-First let us see how to invoke the ``ipython`` interpreter.
+.. R2
-We type
-::
+In this tutorial we will cover the basic usage of the ``ipython``
+interpreter. IPython is an enhanced Python interpreter that provides
+features like tabcompletion, easier access to help and lot of other
+functionality.
+
+.. R3
- ipython
+Let us first see how to start the ``ipython`` interpreter.First
+open the terminal, type ``ipython`` in the terminal and hit enter.
-at the terminal prompt to invoke the ipython interpreter.
+.. L3
+
+::
+ ipython
+
+.. R4
We get a prompt with ``In [1]:`` after getting some information about
-the version of Python installed and some help commands.
+the version of Python installed and some help commands. If you get an
+error showing ``ipython is not installed``, please refer to the
+tutorial on how to install the packages.
+
+.. L4
+
+{{Point to the version information with mouse}}
+{{Point to the In[1]: prompt with mouse}}
+
+.. R5
+
+Now,lets see how we can quit the ipython interpreter, press Ctrl-D.
+
+.. L5
+
+type Ctrl-D.
+
+.. R6
-If you get an error saying something like ``ipython is not
-installed``, refer to the tutorial on how to install the packages
-required for this course.
+A prompt will apperar to confirm whether you really want to exit, type y to say yes and quit ipython
+and n to say no if you dont want to quit the ipython. Press y.
-Now, to quit the ipython interpreter, type Ctrl-D. You are prompted
-asking if you really want to exit, type y to say yes and quit ipython.
+.. L6
+Press y and hit enter.
-Start ipython again, as you did before.
+.. R7
-The prompt that you have says ``In [1]``. ``In`` stands for input and the
-ipython interpreter is ready to accept input from you.
+Now since we have quit the interpretor, let us start it again by typing `` ipython``
-Now let us see, how we can type some commands into the interpreter.
+.. L7
+
+::
+ ipython
+
+.. R8
+
+And now let's see, how to use the interpreter.
Start with the simplest thing, addition.
-Let's type
+type 1+2 at the prompt. IPython promptly gives back the output
+as 3. Notice that the output is displayed with an ``Out[1]``
+indication.
+
+.. L8
+
+::
+
+ 1+2
+
+ {{Point at the Out[1] prompt}}
+
+.. R9
+
+Let us now try few more operations such as, 5 minus 3, 7
+minus 4, 6 into 5.
+
+.. L9
+
::
- 1+2
-at the prompt. IPython promptly gives back the output as 3. Notice
-that the output is displayed with an ``Out[1]`` indication.
+ 5 - 3
+ 7 - 4
+ 6 * 5
+
+.. R10
-.. #[[Anoop: I think we can illustrate In [] and Out[] in slides]]
-.. #[[Puneeth: I think we can do that on the terminal?]]
+Now let's see how the ipython remembers the history of commands ?
+let's try an example ``print 1+2``.
-Let's try out few other mathematical operations.
+Instead of typing the whole thing,use the up arrow key to go back to
+the command ``1+2`` which we did before, now use the
+left-arrow key to navigate to the beginning of the line and type the
+word``print``and press space.We have changed the line to print 1+2, now press enter.
+The interpreter prints the result as 3. Please note that the indication Out square brackets is not shown here.
+
+.. L10
+
+{{Use the up arrow key to go back to the command ``1+2``}}
+{{Use left arrow to navigate to start of line }}
+Type
::
+ 'print'
+{{Hit enter}}
+{{Point at the Out[] prompt}}
+
+.. R11
+
+Now let us do print 10 into 2.
+We use the up arrow key to navigate to the previous command 1+2. Now change ``1 plus 2`` to ``10 into 2`` and press enter.
+
+.. L11
+
+{{{ Change from ``print 1+2`` to ``print 10*2`` }}}
+
+.. R12
+
+Till now, we saw how to invoke the ipython interpreter,quit the ipython and navigate through previous commands in ipython.
+Now, let's see, what is tab-completion?.
+ let's take an example, suppose we want to use the function ``round``. For this we just
+type ``ro``at the prompt and press the tab key.
+
+.. L12
+:: ro<tab>
+
+.. R13
+
+As you can see on the terminal, IPython completes the command ``ro``
+into round, This feature of ipython is called the tab-completion.
+
+.. L13
+
+{{Stay on the terminal}}
- 5 - 3
- 7 - 4
- 6 * 5
+.. R14
-Now let's ``print 1+2``. Instead of typing the whole thing, we make
-use of the fact that IPython remembers the history of the commands
-that you have already used. We use the up arrow key to go back the
-command ``1+2``. We then use the left-arrow key to navigate to the
-beginning of the line and add the word ``print`` and a space. Then hit
-enter and observe that the interpreter prints out the value as 3,
-without the Out[] indication.
+Let's see some more possibilities of tab completion
+just type ``r`` and then press the tab.
-Now, let's change the previous command ``print 1+2`` to ``print
-10*2``. We use the up arrow again to navigate to the previous command
-and use the left arrow key to move the cursor on to the + symbol and
-then use the delete key to remove it and type 0 and * to change the
-expression as required. We hit enter to see the output of
-``print``.
+.. L14
-Now, let's say we want to use the function ``round``. We type ``ro``
-at the prompt and hit the tab key. As you can see, IPython
-completes the command. This feature is called the tab-completion.
+::
+ r<tab>
-Now, we remove all the characters and just type ``r`` and then hit
-tab. IPython does not complete the command since there are many
-possibilities. It just lists out all the possible completions.
+.. R15
-Following is an exercise that you must do.
+ As u can see that IPython does not complete the command. This is
+because, there are many possibilities of ``r`` therefore it just lists
+out all the possible completions of r.
-%%1%% Type ``ab`` and hit tab to see what happens. Next, just type
-``a`` and hit tab to see what happens.
+.. L15
-Please, pause the video here. Do the exercise and then continue.
+{{Stay on the terminal}}
-``ab`` tab completes to ``abs`` and ``a<tab>`` gives us a list of all
+.. L16
+
+{{Show slide with question 1}}
+
+.. R16
+
+Now let's try out an exercise.Pause the video and solve the problem.
+ 1.find out the commands starting with "ab"?
+ 2.list out the commands starting with "a"?
+
+.. R17
+
+``ab`` tab completes to ``abs`` and
+ ``a<tab>`` gives us a list of all
the commands starting with a.
-Now, let's see what these functions are used for. We will use the
-help features of ipython to find this out.
-.. #[[Anoop: Another slide which says about ? mark and round? etc, as
- few people cannot just follow by listening (like me) :)]]
+.. L17
-.. #[Punch: These things are shown on the terminal. I feel we don't
-.. need slide, here I guess.]
+(show solution on terminal/slide)
-To get the help of any function, we first type the function, ``abs``
-in our case and then add a ? at the end and hit enter.
-As the documentation says, ``abs`` accepts a number as an input and
-returns it's absolute value.
+.. R18
+
+Now, let's see what the functions abs is used for. We will use the
+help features of ipython to find out this.
+To see the documentation of a function, type the function name followed by a question mark, and hit enter. Ipython interpreter will show the documentation for the function.
+Lets us see the documentation of the function abs, type abs? and press enter
+
+.. L18
+
+ abs?
+
+
+.. L19
-We say,
::
abs(-19)
abs(19)
-We get 19, as expected, in both the cases.
+.. R19
-Does it work for decimals (or floats)? Let's try typing abs(-10.5)
-and we do get back 10.5.
+As the documentation says, ``abs`` accepts a number as an input and
+returns it's absolute value.
-Following is an exercise that you must do.
+lets see few examples,
-%%2%% Look-up the documentation of ``round`` and see how to use it.
+We get 19, as expected, in both the cases.
+
+.. R20
-Please, pause the video here. Do the exercise and then continue.
+Now lets try it for decimal numbers; lets try abs(-10.5), we got 10.5 as the result.
+
+.. L20
::
+ abs(-10.5)
+
+.. R21
+
+Now try to solve Following exercise,
+%%2%% Look-up the documentation of ``round`` and see how to use it.
+
+.. L21
+
+{{Show slide with question 2}}
+
+.. L22
+
+:: round?
+
+.. R22
- round?
+And you can look up the documentation of the function round by typing round question mark in the ipython interpreter.
-If you notice, there are extra square brackets around the ``ndigits``.
+.. L23
+
+{{highlight the syntax with mouse hover on terminal}}
+
+.. R23
+
+If you notice, there are extra square brackets around ``ndigits``.
This means that ``ndigits`` is optional and 0 is the default value.
-Optional parameters are shown in square brackets anywhere in Python
+Optional parameters are shown in square brackets in Python
documentation.
The function ``round``, rounds a number to a given precision.
-Following are exercises that you must do.
+.. R24
-%%3%% Check the output of::
+Let us now try few more examples with the function round.
+Check the output of
+round(2.48)
+round(2.48,1)
+round(2.48,2)
+round(2.484)
+round(2.484,1)
+round(2.484,2)
- round(2.48)
- round(2.48, 1)
- round(2.48, 2)
+.. L24
- round(2.484)
- round(2.484, 1)
- round(2.484, 2)
+{{Show slide with question 3}}
+
+.. L25
+
+{{Show slide with solution 3}}
-Please, pause the video here. Do the exercises and then continue.
+.. R25
-We get 2.0, 2.5 and 2.48, which are what we expect.
+We got 2.0, 2.5, and 2.48 as expected.
-Let's now see how to correct typing errors that we make while typing at
+.. R26
+
+Let's now see how to correct typing errors which we often make while typing at
the terminal. As already shown, if we haven't hit the enter key
already, we could navigate using the arrow keys and make deletions
using delete or backspace key and correct the errors.
-Let's now type round(2.484 and hit enter, without closing the
-parenthesis. We get a prompt with dots. This prompt is the
-continuation prompt of ``ipython``. It appears, the previous line is
-incomplete in some way. We now complete the command by typing, the
-closing parenthesis and hitting enter. We get the expected output of
-2.5.
+let us make a typing error deliberately,
+type
+::
+ round(2.484
+ and hit enter, without closing the parenthesis.
+
+.. L26
+
+::
+ round(2.484
+
+{{Hit enter}}
+
+.. R27
+
+We get a prompt with dots. This prompt is the continuation prompt of
+``ipython``. It appears when, the previous line is incomplete. now
+complete the command of the same examples with close parenthesis and
+press enter. We got the expected output that is 2.0
+
+.. L27
+{{ Point at the prompt with three dots }}
+::
+ )
+
+.. R28
In other instances, if we commit a typing error with a longer and more
complex expression and end up with the continuation prompt, we can
-type Ctrl-C to interrupt the command and get back the ``ipython`` input
-prompt.
+type Ctrl-C to interrupt the command and to get back to the
+``ipython`` input prompt.
+
+.. L28
+
+<Type any big random number>
+::
+
+ round(35.488762320
+ Ctrl-C
-Following is an exercise that you must do.
+.. R29
-%%4%% Try typing round(2.484, and hit enter. and then cancel the
-command using Ctrl-C. Then, type the command, round(2.484, 2) and
-resume the video.
+Try the following exercise
+1. type round(2.484, and press enter. and then cancel the
+command using Ctrl-C.
+2. type the command, round(2.484, 2)
-Please, pause the video here. Do the exercises and then continue.
+.. L29
+
+{{Show slide with question 4}}
+
+
+.. L30
+
+{ show the solution on terminal and slide }
::
-
round(2.484
^C
round(2.484, 2)
+
+.. R30
+
+.. L31
+
+{{{ show the summary slide and read out the same }}}
+
+.. R31
+
+let's revise quickly what we have learnt today.
+
+ 1. to invoke the ``ipython`` interpreter by typing ipython.
+ #. to quit the ``ipython`` interpreter by using <ctrl>d.
+ #. to navigate in the history of ``ipython`` by using the arrow keys.
+ #. what is tab-completion.
+ #. to see the documentation of functions using question mark.
+ #. to interrupt using <ctrl>c when we make an error.
+
+.. R32
-This brings us to the end of the tutorial on getting started with
-``ipython``.
+Here are some self assessment questions for you to solve
+ {{Show self assessment questions slide}}
+Here are some self assessment questions for you to solve
+
+1. Ipython is a programming similar to Python?
+ True or False
+
+2. Which key combination quits “ipython”?
+ Ctrl + C
+ Ctrl + D
+ Alt + C
+ Alt + D
+
+3. Which character is used at the end of a command, in Ipython to display the documentation.
+ under score (_)
+ question mark (?)
+ exclamation mark (!)
+ ampersand (&)
+
+.. L32
+
+{{Show self assessment questions slide}}
+
-.. #[[Anoop: add slides for interrupts, navigating history, I feel
- even a single point will also do]]
+.. L33
-.. #[Puneeth: I don't feel these things cannot be shown on a slide.]
+(solution of self assessment questions on slide)
-In this tutorial we have learnt, how to
-{{{ show the outline/summary slide. }}}
- 1. invoke the ``ipython`` interpreter.
- #. quit the ``ipython`` interpreter.
- #. navigate in the history of ``ipython``.
- #. use tab-completion.
- #. look-up documentation of functions.
- #. interrupt incomplete or incorrect commands.
+.. R33
-{{{ Show the "sponsored by FOSSEE" slide }}}
+And the answers,
+1. Ipython is not a programming language, it is just an interpreter.
+2. We use Ctrl D to quit Ipython interpreter.
+3. We use ? at the end of the function name to display its documentation.
-This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
+.. L34
+{{a thank you slide}}
+.. R34
Hope you have enjoyed and found it useful.
Thank you!