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