Python-3.4.3/C2/Getting-started-with-IPython/English-timed

From Script | Spoken-Tutorial
Revision as of 16:46, 11 June 2019 by Sandhya.np14 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Time
Narration
00:01 Hello friends. 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,
00:13 quit the IPython interpreter,
00:16 navigate the IPython session history,
00:20 use tab-completion within IPython,
00:23 look up documentation in IPython,
00:26 interrupt incomplete or incorrect commands.
00:30 To record this tutorial, I am using:

Ubuntu Linux 14.04 operating system,

00:37 Python 3.5.2,

IPython 5.1.0

00:44 What is IPython?

IPython is an enhanced interactive Python interpreter.

00:50 It provides features like tab-completion and easier access to help.
00:56 Let us first see how to start the IPython interpreter.
01:00 First open the terminal by pressing Ctrl+Alt+T keys simultaneously on the keyboard.
01:07 Type ipython3 at the prompt and press Enter.
01:13 If IPython is not installed, please refer to the Instruction sheet.
01:18 If IPython is installed, the IPython interpreter is loaded by running the ipython command in the terminal.
01:25 The versions of Python and IPython that are installed, are shown on the terminal.
01:32 Some additional helpful information is printed by IPython.
01:37 After this, we get a prompt with i n bracket 1:
01:42 Now, let us see how we can quit the IPython interpreter.

Press Ctrl+D keys.

01:48 A prompt will appear to confirm if we really want to exit.
01:53 Type y for yes and quit IPython.
01:57 Note that y is given in square brackets. So, it is default.
02:02 We could also press Enter and it will exit.
02:05 Else, type n for no if you don't want to quit IPython.
02:10 Let us type y.

We have quit IPython interpreter and are back at the terminal prompt.

02:16 Let us start it again.

Type ipython3 in the terminal and press Enter.

02:23 Now, let us learn how to use the interpreter.

Let us start with the simplest operation - addition.

02:30 Type: 1 plus 2 at the IPython prompt and press Enter.
02:36 We press Enter to execute the python command. Please do so, after typing every command.
02:43 IPython promptly displays the output as 3.
02:47 Notice that the output is shown with an Out square brackets 1 indication.
02:54 Let us now try a few more operations such as-

5 minus 3,

7 multiplied by 4.

03:03 Each time we press Enter and see the output on the IPython console window.
03:10 Let us see how we can navigate to previous commands in IPython.
03:15 For example, say, we want to execute print open parenthesis 1 plus 2 close parenthesis.
03:23 Instead of typing the whole command, we can recall the command 1 plus 2 we typed earlier.
03:30 Use the up arrow key to go back to the command 1 plus 2.
03:35 Now use the left-arrow key to navigate to the beginning of the line.
03:40 Type the word print, open parenthesis close parenthesis, on the keyboard.
03:49 We have changed the command to print (1 plus 2). Now press Enter.
03:53 The interpreter prints the result as 3.

Notice that this time, the indication Out square brackets, is not displayed.

04:03 Now let us execute print 10 multiplied by 2.

We use the up arrow key to navigate to the previous command print (1 plus 2).

04:14 Now replace 1 plus 2 with 10 multiplied by 2 and press Enter.
04:21 As with any programming language, asterisk is used for multiplication operator.
04:27 Observe the output on the console.
04:30 Now, let us see, what is tab-completion.

Let us consider an example.

04:35 Suppose we want to use the function "print".
04:39 For this, we just type pri at the prompt and press the tab key.
04:45 As you can see on the console that IPython has autocompleted the command pri to print.
04:52 This feature of IPython is called the tab-completion.
04:56 Let us see some more possibilities of tab completion.

Just type p and then press the tab.

05:05 In this case, we see that IPython does not complete the command.
05:09 This is because, there are more than one command beginning with p.
05:14 Therefore, it just lists out all the possible tab-completions of p.
05:20 Now let us try out an exercise.
05:23 Pause the video, solve the problem and resume the video.

Find out the commands starting with "ab".

05:31 List out the commands starting with "a".
05:35 ab autocompletes to a b s abs.
05:40 a tab displays a list of all the commands starting with a.
05:46 Now, let us see what the function abs is used for.
05:51 We will use the help feature of IPython to find out this.
05:55 To see the documentation of a function, type the function name followed by a question mark.
06:03 The IPython interpreter will show the documentation for the function.
06:08 From the displayed information, it says abs accepts a number as input and returns it's absolute value.
06:16 Let us see a few examples. On the console, type: a b s minus 19 and then a b s 19.
06:29 We get 19, as expected, in both the cases.
06:33 Now let us try it for decimal numbers.

Let us try a b s minus 10.5.

06:42 We get 10.5 as the result.
06:46 Pause the video here.

Try out the following exercise and resume the video.

06:52 Look-up the documentation of round and see how to use it.
06:57 Switch to the console for the solution.

You can look up the documentation of the function round by typing round question mark.

07:06 It says here that the function 'round', rounds a number to a given precision.
07:12 ndigits is the precision value for round function.

Notice, there are extra square brackets around ndigits.

07:21 This means that ndigits is optional and 0 is the default value.
07:27 Optional parameters are shown in square brackets in Python documentation.
07:33 Pause the video here.

Try out the following exercise and resume the video.

07:38 Check the output of:

round 2.48, round 2.48 comma 1, round 2.484, round 2.484 comma 2

07:52 We get round 2.48 is equal to 2.0,
07:57 round 2.48 comma 1 is 2.5,
08:02 round 2.484 is 2.0,
08:06 round 2.484 comma 2 is 2.48

which are what we expect.

08:13 Let us now see how to correct typing errors which we could make while typing on the console.
08:20 Let us make a typing error deliberately.

Type: round open parenthesis 2.484 and press Enter, without closing the parenthesis.

08:32 We get a prompt with dots.

This prompt is the continuation prompt of IPython.

08:40 It appears when the previous line is incomplete.
08:44 Now complete the command with close parenthesis and press Enter.

We get the expected output, that is 2.

08:54 What if we type an incorrect command and end up with the continuation prompt?
09:00 In such case, we can press Ctrl+C keys to interrupt the command and get back to the IPython prompt.
09:09 round takes only numbers as input. Type: round(1a
09:15 Do not close the parenthesis and press Enter.
09:19 We gave alpha-numeric value '1 a' as input.

Press Ctrl+C to interrupt the execution.

09:28 Pause the video here.

Try out the following exercise and resume the video.

09:34 Type: round 2.484, without closing the parenthesis and press Enter.
09:41 Then cancel the command using Ctrl+C. Type the command round 2.484 comma 2
09:51 The output on your console should look like this.
10:01 This brings us to the end of this tutorial.
10:04 In this tutorial, we have learnt to:

invoke the IPython interpreter by typing ipython in the terminal,

10:13 quit the IPython interpreter by using Ctrl+D,
10:17 navigate the IPython session history by using the arrow keys,
10:23 Use tab-completion to work faster,
10:27 see the documentation of functions using question mark,
10:32 interrupt commands using Ctrl+C when we make an error.
10:37 Here are some self assessment questions for you to solve.
10:41 IPython is a programming language similar to Python. True or False
10:46 Which key combination quits IPython?

Ctrl + C

Ctrl + D

Alt + C

Alt + D

10:55 Which character is used at the end of a command in IPython to display the documentation?

under score

question mark

exclamation mark

ampersand

11:07 And, the answers are- False. IPython is not a new programming language. It is just an enhanced interactive Python interpreter.
11:17 We use Ctrl + D to quit IPython interpreter.
11:21 We use question mark (?) at the end of the command to display its documentation.
11:28 This video summarises the Spoken Tutorial project.

If you do not have good bandwidth, you may download and watch it.

11:37 We conduct workshops, give certificates. Please contact us.
11:42 Do you have questions in THIS Spoken Tutorial?

Choose the minute and second where you have the question.

11:48 Explain your question briefly. Someone from the FOSSEE team will answer them.

Please visit this site.

11:56 Do you have any general / technical questions in Python?
11:59 Please visit the FOSSEE forum and post your question.
12:04 The FOSSEE team coordinates coding of several solved examples of popular books.
12:10 We give honorarium and certificates for those who do this.

For more details, please visit this site.

12:17 The Spoken Tutorial project is funded by NMEICT, MHRD, Govt. of India.
12:23 This is Prabhu from IIT Bombay, signing off. Thanks for watching.

Contributors and Content Editors

PoojaMoolya, Sandhya.np14