Difference between revisions of "Python-3.4.3/C2/Getting-started-with-IPython/English"
(→Python/C2/Getting-started-with-IPython/English) |
Nancyvarkey (Talk | contribs) |
||
(One intermediate revision by one other user not shown) | |||
Line 28: | Line 28: | ||
# invoke the '''IPython interpreter'''. | # invoke the '''IPython interpreter'''. | ||
# quit the '''IPython interpreter'''. | # quit the '''IPython interpreter'''. | ||
− | # navigate the '''IPython''' | + | # navigate the '''IPython session''' history. |
# use '''tab-completion''' within '''IPython'''. | # use '''tab-completion''' within '''IPython'''. | ||
− | # look | + | # look up documentation in '''IPython'''. |
# interrupt incomplete or incorrect '''commands'''. | # interrupt incomplete or incorrect '''commands'''. | ||
− | |||
− | |||
|- | |- | ||
Line 44: | Line 42: | ||
* '''Python 3.5.2''' | * '''Python 3.5.2''' | ||
* '''IPython 5.1.0''' | * '''IPython 5.1.0''' | ||
− | |||
− | |||
|- | |- | ||
Line 53: | Line 49: | ||
| style="border:0.5pt solid #000000;padding:0.0417in;"| What is '''IPython'''? | | style="border:0.5pt solid #000000;padding:0.0417in;"| What is '''IPython'''? | ||
− | * '''IPython''' is an enhanced '''interactive | + | * '''IPython''' is an enhanced '''interactive Python interpreter.''' |
* It provides features like '''tab-completion''', and easier access to help. | * It provides features like '''tab-completion''', and easier access to help. | ||
− | |||
− | |||
|- | |- | ||
Line 70: | Line 64: | ||
Type '''ipython3''' at the '''prompt''' and press '''Enter'''. | Type '''ipython3''' at the '''prompt''' and press '''Enter'''. | ||
− | If '''IPython''' is not installed, please refer to the | + | If '''IPython''' is not installed, please refer to the '''Instruction sheet'''. |
|- | |- | ||
Line 84: | Line 78: | ||
| style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.0417in;"| [IPython Terminal] | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.0417in;"| [IPython Terminal] | ||
− | |||
| style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.0417in;"| Some additional helpful information is printed by '''IPython.''' | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.0417in;"| Some additional helpful information is printed by '''IPython.''' | ||
+ | |- | ||
+ | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.0417in;"| Point to '''In[1]''': prompt with mouse | ||
− | After this, we get a prompt with ''' | + | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.0417in;"| After this, we get a prompt with '''i n bracket 1''': |
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
Line 97: | Line 89: | ||
Type '''Ctrl+D''' | Type '''Ctrl+D''' | ||
− | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| Now, | + | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| Now, let us see how we can quit the '''IPython interpreter'''. |
Line 144: | Line 136: | ||
|- | |- | ||
| style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| [IPython Terminal] | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| [IPython Terminal] | ||
− | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| Now, | + | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| Now, let us learn how to use the interpreter. |
Line 161: | Line 153: | ||
− | We press '''Enter''' to execute the '''python | + | We press '''Enter''' to execute the '''python command'''. Please do so after typing every '''command'''. |
Line 193: | Line 185: | ||
− | Instead of typing the whole '''command''', we can recall the '''command | + | Instead of typing the whole '''command''', we can recall the '''command 1 plus 2 '''we typed earlier. |
|- | |- | ||
Line 206: | Line 198: | ||
Use left arrow to navigate to start of line | Use left arrow to navigate to start of line | ||
| style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| Now use the left-arrow key to navigate to the beginning of the line. | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| Now use the left-arrow key to navigate to the beginning of the line. | ||
− | |||
− | |||
− | |||
|- | |- | ||
Line 217: | Line 206: | ||
− | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| Type the word '''print open parenthesis | + | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| Type the word '''print open parenthesis close parenthesis '''on the keyboard. |
We have changed the '''command''' to '''print (1 plus 2). '''Now press '''Enter'''. | We have changed the '''command''' to '''print (1 plus 2). '''Now press '''Enter'''. | ||
− | |||
− | |||
− | |||
|- | |- | ||
Line 252: | Line 238: | ||
− | As with any programming language, '''asterix '''is used for multiplication operator. | + | As with any programming language, '''asterix '''is used for '''multiplication operator'''. |
|- | |- | ||
Line 258: | Line 244: | ||
Highlight output | Highlight output | ||
− | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| Observe the output on the console. | + | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| Observe the output on the '''console'''. |
<<PAUSE>> | <<PAUSE>> | ||
Line 264: | Line 250: | ||
|- | |- | ||
| style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| [IPython Terminal] | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| [IPython Terminal] | ||
− | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| Now, | + | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| Now, let us see, what is '''tab-completion'''. |
Line 276: | Line 262: | ||
− | For this we just type '''pri''' at | + | For this we just type '''pri''' at the '''prompt''' and press the '''tab key'''. |
|- | |- | ||
| style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| [IPython Terminal] | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| [IPython Terminal] | ||
− | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| As you can see on the console that '''IPython''' has autocompleted the '''command''' '''pri''' to '''print'''. | + | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| As you can see on the '''console''' that '''IPython''' has autocompleted the '''command''' '''pri''' to '''print'''. |
Line 302: | Line 288: | ||
− | Therefore, it just lists out all the possible '''tab- | + | Therefore, it just lists out all the possible '''tab-completions''' of '''p'''. |
|- | |- | ||
Line 308: | Line 294: | ||
Exercise 1 | Exercise 1 | ||
− | | style="border:0.5pt solid #000000;padding:0.0417in;"| Now | + | | style="border:0.5pt solid #000000;padding:0.0417in;"| Now let us try out an exercise. |
Line 315: | Line 301: | ||
# find out the '''commands''' starting with "'''ab'''". | # find out the '''commands''' starting with "'''ab'''". | ||
# list out the '''commands''' starting with "'''a'''". | # list out the '''commands''' starting with "'''a'''". | ||
− | |||
− | |||
|- | |- | ||
Line 325: | Line 309: | ||
'''a'''<tab> | '''a'''<tab> | ||
− | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| '''ab''' | + | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| '''ab tab''' autocompletes to '''a b s abs'''. |
+ | |||
− | + | '''a tab''' displays a list of all the '''commands''' starting with '''a'''. | |
− | '''a''' | + | |
|- | |- | ||
| style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| [IPython Terminal] | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| [IPython Terminal] | ||
− | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| Now, | + | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| Now, let us see what the '''function abs '''is used for. |
Line 342: | Line 326: | ||
− | '''IPython interpreter '''will show the documentation for the '''function | + | The '''IPython interpreter '''will show the documentation for the '''function'''. |
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
Line 352: | Line 333: | ||
Type '''abs'''? >> press '''Enter''' | Type '''abs'''? >> press '''Enter''' | ||
− | + | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| From the displayed information, it says '''abs''' accepts a number as input and returns it's absolute value. | |
− | + | ||
− | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| | + | |
|- | |- | ||
Line 362: | Line 341: | ||
'''abs(19) ''' | '''abs(19) ''' | ||
− | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| Let us see few examples | + | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| Let us see a few examples. |
− | On the '''console''', type ''' | + | On the '''console''', type '''a b s minus 19''' and then '''a b s 19'''. |
Line 374: | Line 353: | ||
'''abs(-10.5) ''' | '''abs(-10.5) ''' | ||
− | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| Now | + | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| Now let us try it for decimal numbers. |
− | Let us try ''' | + | Let us try '''a b s minus 10.5'''. |
Line 405: | Line 384: | ||
− | You can look up the documentation of the '''function round''' by typing '''round | + | You can look up the documentation of the '''function round''' by typing '''round question mark'''. |
− | It says here that the '''function round | + | It says here that the '''function round, rounds''' a number to a given '''precision'''. |
|- | |- | ||
Line 414: | Line 393: | ||
Highlight the syntax of '''ndigits ''' | Highlight the syntax of '''ndigits ''' | ||
− | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| '''ndigits '''is the | + | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| '''ndigits '''is the '''precision''' value for '''round function'''. |
Line 436: | Line 415: | ||
Check the output of | Check the output of | ||
− | '''round | + | '''round 2.48 round 2.48 comma 1 round 2.484 round 2.484 comma 2 ''' |
|- | |- | ||
Line 444: | Line 423: | ||
| style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| We get | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| We get | ||
− | + | '''round 2.48 is equal to 2.0''' | |
− | '''round | + | '''round 2.48 comma 1 is 2.5''' |
+ | '''round 2.484 is 2.0''' | ||
+ | '''round 2.484 comma 2 is 2.48 ''' | ||
Line 463: | Line 444: | ||
− | Type '''round open parenthesis 2.484''' and press '''Enter''', without closing the parenthesis. | + | Type '''round open parenthesis 2.484''' and press '''Enter''', without closing the '''parenthesis'''. |
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
Line 478: | Line 456: | ||
− | This '''prompt '''is the | + | This '''prompt '''is the '''continuation prompt '''of '''IPython'''. |
− | It appears when | + | It appears when the previous line is incomplete. |
|- | |- | ||
Line 488: | Line 466: | ||
− | We get the expected output, that is 2. | + | We get the expected output, that is 2. |
|- | |- | ||
Line 501: | Line 479: | ||
− | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| What if we type an incorrect '''command '''and end up with the | + | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding-top:0in;padding-bottom:0.0417in;padding-left:0.0417in;padding-right:0.0417in;"| What if we type an incorrect '''command '''and end up with the '''continuation prompt'''? |
Line 510: | Line 488: | ||
− | Do not close the | + | Do not close the '''parenthesis''' and press''' Enter. ''' |
− | We gave alpha-numeric value '''' | + | We gave alpha-numeric value ''''1 a'''' as input. |
− | Press''' Ctrl+C''' to | + | Press''' Ctrl+C''' to interrupt the execution. |
|- | |- | ||
Line 527: | Line 505: | ||
Try out the following exercise and resume the video. | Try out the following exercise and resume the video. | ||
− | # Type '''round | + | # Type '''round 2.484,''' without closing the '''parenthesis''' and press '''Enter'''. |
# Then cancel the '''command''' using '''Ctrl+C'''. | # Then cancel the '''command''' using '''Ctrl+C'''. | ||
− | # Type the '''command | + | # Type the '''command round 2.484 comma 2 ''' |
− | + | ||
− | + | ||
|- | |- | ||
Line 556: | Line 532: | ||
In this tutorial,we have learnt to, | In this tutorial,we have learnt to, | ||
− | # invoke the '''IPython interpreter '''by typing | + | # invoke the '''IPython interpreter '''by typing '''ipython''' in the '''terminal'''. |
# quit the '''IPython interpreter '''by using '''Ctrl+D'''. | # quit the '''IPython interpreter '''by using '''Ctrl+D'''. | ||
− | # navigate '''IPython''' | + | # navigate the '''IPython session''' history by using the arrow keys. |
# use the '''tab-completion''' to work faster. | # use the '''tab-completion''' to work faster. | ||
# see the documentation of '''functions '''using '''question mark'''. | # see the documentation of '''functions '''using '''question mark'''. | ||
# interrupt commands using '''Ctrl+C''' when we make an error. | # interrupt commands using '''Ctrl+C''' when we make an error. | ||
− | |||
− | |||
|- | |- | ||
Line 572: | Line 546: | ||
− | | style="border:0.5pt solid #000000;padding:0.0417in;"| Here are some self assessment questions for you to solve | + | | style="border:0.5pt solid #000000;padding:0.0417in;"| Here are some self assessment questions for you to solve. |
− | # '''IPython | + | # '''IPython is a programming language similar to Python.'''True or False <br/> |
− | + | ||
# Which key combination quits '''IPython'''? | # Which key combination quits '''IPython'''? | ||
− | + | #* '''Ctrl + C''' | |
− | + | #* '''Ctrl + D''' | |
− | + | #* '''Alt + C''' | |
− | + | #* '''Alt + D''' <br/> | |
− | + | # Which character is used at the end of a '''command''', in '''IPython''' to display the documentation? | |
− | + | #* '''under score ''' | |
− | + | #* '''question mark ''' | |
− | + | #* '''exclamation mark ''' | |
− | + | #* '''ampersand ''' <br/> | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
Line 606: | Line 570: | ||
| style="border:0.5pt solid #000000;padding:0.0417in;"| And the answers are- | | style="border:0.5pt solid #000000;padding:0.0417in;"| And the answers are- | ||
− | + | # '''False. IPython''' is not a new programming language. It is just an enhanced interactive '''Python interpreter'''. | |
− | # '''False. IPython''' is not a new programming language. It is just an enhanced interactive '''Python | + | |
# We use '''Ctrl + D''' to quit '''IPython interpreter'''. | # We use '''Ctrl + D''' to quit '''IPython interpreter'''. | ||
− | # We use '''? '''at the end of the command to display its documentation. | + | # We use '''? '''at the end of the '''command''' to display its documentation. |
− | + | ||
− | + | ||
|- | |- | ||
Line 653: | Line 614: | ||
Forum to answer questions | Forum to answer questions | ||
− | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.0417in;"| Do you have any general / technical questions | + | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.0417in;"| Do you have any general / technical questions in '''Python'''? |
− | Please visit the FOSSEE forum and post your question. | + | Please visit the '''FOSSEE forum''' and post your question. |
|- | |- | ||
Line 661: | Line 622: | ||
Textbook Companion | Textbook Companion | ||
− | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.0417in;"| The '''FOSSEE '''team coordinates coding of solved examples of popular books. | + | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.0417in;"| The '''FOSSEE '''team coordinates coding of several solved examples of popular books. |
We give honorarium and certificates for those who do this. | We give honorarium and certificates for those who do this. | ||
Line 677: | Line 638: | ||
Thank You | Thank You | ||
− | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.0417in;"| This is | + | | style="border-top:none;border-bottom:0.5pt solid #000000;border-left:0.5pt solid #000000;border-right:0.5pt solid #000000;padding:0.0417in;"| This is Prabhu from IIT Bombay signing off. Thanks for watching |
|} | |} |
Latest revision as of 07:37, 10 February 2017
Python/C2/Getting-started-with-IPython/English
Title of script: Getting started with IPython
Author: Puneeth, Jovina, Thirumalesh H S
Keywords: Python, IPython
|
|
Show Slide
[Slide with MHRD logo] |
Hello Friends. Welcome to the spoken tutorial on "getting started with IPython". |
Show Slide
Objectives
|
At the end of this tutorial, you will be able to,
|
Show Slide
System Specifications |
To record this tutorial, I am using
|
Show Slide:
What is IPython |
What is IPython?
|
[Terminal]
Type ipython >> press Enter |
Let us first see how to start the IPython interpreter.
If IPython is not installed, please refer to the Instruction sheet. |
[IPython Terminal]
Point to the version information with mouse. |
If IPython is installed, the IPython interpreter is loaded by running the ipython command in the terminal
|
[IPython Terminal] | Some additional helpful information is printed by IPython. |
Point to In[1]: prompt with mouse | After this, we get a prompt with i n bracket 1: |
[IPython Terminal]
Type Ctrl+D |
Now, let us see how we can quit the IPython interpreter.
|
]IPython Terminal]
|
A prompt will appear to confirm if we really want to exit.
We could also press Enter and it will exit.
|
[IPython Terminal]
|
Let us type y.
|
[Terminal]
Type ipython >> press Enter |
Let us start it again.
|
[IPython Terminal] | Now, let us learn how to use the interpreter.
|
[IPython Terminal]
1+2 Point at the Out[1] prompt
|
Type 1 plus 2 at the IPython prompt and press Enter.
|
[IPython Terminal]
5 – 3 7 * 4 |
Let us now try a few more operations such as,
5 minus 3, 7 multiplied by 4,
|
IPython Terminal | Let us see how we can navigate to previous commands in IPython |
[IPython Terminal] | For example, say, we want to execute print open parenthesis 1 plus 2 close parenthesis.
|
[IPython Terminal]
Use the up arrow key to go back to the command 1+2. |
Use the up arrow key to go back to the command 1 plus 2. |
[IPython Terminal]
Use left arrow to navigate to start of line |
Now use the left-arrow key to navigate to the beginning of the line. |
[IPython Terminal]
Type print (>> press space) and press Enter.
|
Type the word print open parenthesis close parenthesis on the keyboard.
|
[IPython Terminal]
Highlight the result line.
|
The interpreter prints the result as 3.
|
[IPython Terminal]
Press up-arrow key |
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). |
[IPython Terminal]
Change print (1+2) to print (10*2) |
Now replace 1 plus 2 with 10 multiplied by 2 and press Enter.
|
[IPython Terminal]
Highlight output |
Observe the output on the console.
<<PAUSE>> |
[IPython Terminal] | Now, let us see, what is tab-completion.
|
[IPython Terminal]
pri<tab> |
Suppose we want to use the function print.
|
[IPython Terminal] | As you can see on the console that IPython has autocompleted the command pri to print.
|
[IPython Terminal]
p<tab> |
Let us see some more possibilities of tab completion.
|
[IPython Terminal] | In this case, we see that IPython does not complete the command.
|
Show Slide:
Exercise 1 |
Now let us try out an exercise.
|
[IPython Terminal]
a<tab> |
ab tab autocompletes to a b s abs.
|
[IPython Terminal] | Now, let us see what the function abs is used for.
|
[IPython Terminal] | To see the documentation of a function, type the function name followed by a question mark.
|
[IPython Terminal]
Type abs? >> press Enter |
From the displayed information, it says abs accepts a number as input and returns it's absolute value. |
[Ipython Terminal]
abs(-19) abs(19) |
Let us see a few examples.
|
[Ipython Terminal]
abs(-10.5) |
Now let us try it for decimal numbers.
|
Show Slide
Exercise 2 round? |
Pause the video here.
Try out the following exercise and resume the video.
|
[IPython Terminal]
Type round?
|
Switch to the console for the solution.
|
[IPython Terminal]
Highlight the syntax of ndigits |
ndigits is the precision value for round function.
|
Show Slide
Exercise 3 |
Pause the video here.
Check the output of round 2.48 round 2.48 comma 1 round 2.484 round 2.484 comma 2 |
Show Slide
Solution 3 |
We get
round 2.48 is equal to 2.0 round 2.48 comma 1 is 2.5 round 2.484 is 2.0 round 2.484 comma 2 is 2.48
|
[IPython Terminal]
Press Enter |
Let us now see how to correct typing errors, which we could make while typing on the console.
|
[IPython Terminal]
Point at the prompt with three dots
|
We get a prompt with dots.
|
Type ) >> press Enter | Now complete the command with close parenthesis and press Enter.
|
[IPython Terminal]
|
What if we type an incorrect command and end up with the continuation prompt?
|
Show Slide
Exercise 4 |
Pause the video here.
|
[IPython Terminal]
round(2.484 Ctrl+C round(2.484, 2) |
The output on your console should look like this. |
Show Slide
|
This brings us to the end of this tutorial.
|
Show Slide
Assignment
|
Here are some self assessment questions for you to solve.
|
Show Slide
Solutions
|
And the answers are-
|
Show Slide
About the Spoken Tutorial Project
|
This video summarises the Spoken Tutorial project.
|
Show Slide
Spoken tutorial workshops |
We conduct workshops using Spoken Tutorials.
Give Certificates. Please contact us. |
Show Slide
Forum to answer questions |
Do you have questions in THIS Spoken Tutorial?
Choose the minute and second where you have the question. Explain your question briefly. Someone from the FOSSEE team will answer them. Please visit this site. |
Show Slide
Forum to answer questions |
Do you have any general / technical questions in Python?
Please visit the FOSSEE forum and post your question. |
Show Slide
Textbook Companion |
The FOSSEE team coordinates coding of several solved examples of popular books.
We give honorarium and certificates for those who do this. For more details, please visit this site. |
Show Slide
Acknowledgement |
The Spoken Tutorial project is funded by NMEICT, MHRD, Govt. of India |
Show Slide
Thank You |
This is Prabhu from IIT Bombay signing off. Thanks for watching |