Python/C2/Getting-started-with-ipython/English-timed

From Script | Spoken-Tutorial
Revision as of 16:14, 2 January 2013 by Minal (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Timing Narration
0:00 Hello Friends and Welcome to the tutorial on "getting started with ipython".
0:06 At the end of this tutorial, you will be able to,
  1. invoke the ipython interpreter .
  2. quit the ipython interpreter.
  3. navigate the ipython session history.
  4. use tab-completion for writing ipython functions.
  5. look-up documentation of functions.
  6. interrupt incomplete or incorrect commands.


0:26 IPython is an enhanced Python interpreter that provides features like tab-completion, easier access to help and many other functionalities.
0:36 Let us first see how to start the ipython interpreter.
0:40 First open the terminal, type ipython in the terminal and hit enter.
0:50 After getting some information about the version of Python installed and some help commands, we get a prompt with In[1]:.
0:59 But, if you get an error saying 'ipython is not installed' then refer to the tutorial on how to install the packages.
1:07 Now, lets see how we can quit the ipython interpreter, press Ctrl-D.
1:17 A prompt will appear to confirm whether you really want to exit, type y to say yes and quit ipython and n to say no if you don't want to quit the ipython.
1:27 Press y.
1:31 Now since we have quit the interpretor, let us start it again by typing ipython
1:41 And now let's see, how to use the interpreter.
1:45 Start with the simplest thing, addition.
1:48 type 1+2 at the prompt.
1:54 IPython promptly gives back the output as 3.
1:58 Notice that the output is displayed with an Out[1] indication.
2:05 Now, Let us now try few more operations such as, 5 minus 3, 7 minus 4, 6 into 5.
2:22 Now let's see how the ipython remembers the history of commands.
2:28 For example print 1+2.
2:32 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.
2:54 We have changed the line to print 1+2, now press enter.
3:01 The interpreter prints the result as 3.
3:04 Please note that the indication Out square brackets is not shown here.
3:10 Now let us do print 10 into 2.
3:14 We use the up arrow key to navigate to the previous command 1+2.
3:21 Now change 1 plus 2 to 10 into 2 and press enter.
3:33 Till now, we saw how to invoke the ipython interpreter,quit the ipython and navigate through previous commands in ipython.
3:41 Now, let's see, what is tab-completion?.
3:45 let's take an example, suppose we want to use the function round.
3:50 For this we just type ro at the prompt and press the tab key.
3:59 As you can see on the terminal, IPython completes the command ro into round, This feature of ipython is called the tab-completion.
4:08 Let's see some more possibilities of tab completion just type r and then press the tab.
4:18 As you 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.
4:30 Now let's try out an exercise.
4:32 Pause the video,solve the problem and resume the video.
4:38 1. find out the commands starting with "ab"?
4:43 2. list out the commands starting with "a"?
4:53 ab tab completes to abs and a<tab> gives us a list of all the commands starting with a.
5:06 Now, let's see what the functions abs is used for.
5:11 We will use the help features of ipython to find out this.
5:15 To see the documentation of a function, type the function name followed by a exercise mark.
5:23 Ipython interpreter will show the documentation for the function.
5:27 Let us see the documentation of the function abs, type abs? and press enter
5:37 As the documentation says, abs accepts a number as an input and returns it's absolute value.
5:45 lets see few examples,
5:48 Type abs(-19) and abs(19) on the interpreter.
6:03 We get 19, as expected, in both the cases.
6:07 Now lets try it for decimal numbers; lets try abs(-10.5), we got 10.5 as the result.
6:23 Pause the video here, try out the following exercise and resume the video.
6:30 Look-up the documentation of round and see how to use it.
6:38 And you can look up the documentation of the function round by typing round exercise mark in the ipython interpreter.
6:47 If you notice, there are extra square brackets around ndigits.
6:52 This means that ndigits is optional and 0 is the default value.
6:57 Optional parameters are shown in square brackets in Python documentation.
7:02 The function round, rounds a number to a given precision.
7:08 Pause the video here, try out the following exercise and resume the video.
7:15 et us now try few more examples with the function round.
7:19 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)
7:42 Now, we get 2.0, 2.5 and 2.48, which are what we expect.
7:54 Let's now see how to correct typing errors which we often make while typing at the terminal.
7:59 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.
8:11 let us make a typing error deliberately, type round(2.484 and hit enter, without closing the parenthesis.
8:24 We get a prompt with dots.
8:27 This prompt is the continuation prompt of ipython.
8:31 It appears when, the previous line is incomplete.
8:35 now complete the command of the same examples with close parenthesis and press enter.
8:48 We got the expected output that is 2.0
8:51 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 to get back to the ipython input prompt.
9:15 Pause the video here, try out the following exercise and resume the video.
9:22 1. type round(2.484, and press enter. and then cancel the command using Ctrl-C.
9:45 2. type the command, round(2.484, 2)
10:08 Now, let us revise quickly what we learnt today. In this tutorial,we have learnt to,
10:15 1. Invoke the ipython interpreter by typing ipython.
10:18 2. To quit the ipython interpreter by using <ctrl>d.
10:22 3. To navigate in the history of ipython by using the arrow keys.
10:28 4. What is tab-completion
10:29 5. To see the documentation of functions using exercise mark.
10:32 6. To Interrupt using <ctrl>c when we make an error.
10:37 Here are some self assessment questions for you to solve
10:42 ipython is a programming language similar to Python.
10:50
True or False
10:52 Second one. Which key combination quits ipython? Ctrl + C Ctrl + D Alt + C Alt + D
11:02 The last one. Which character is used at the end of a command, in Ipython to display the documentation. under score (_) exercise mark (?) exclamation mark (!) ampersand (&)
11:15 And the answers are,
11:18 Ipython is not a programming language, it is just an interpreter.
11:22 Second one is We use Ctrl D to quit Ipython interpreter.
11:27 The final one is We use ? at the end of the function name to display its documentation.
11:35 So we hope you have enjoyed this tutorial and found it useful.
11:39 Thank you!

Contributors and Content Editors

Devraj, Gaurav, Minal, PoojaMoolya, Sandhya.np14, Sneha