 Hi everyone this is the lower the programming class essentially we covered several topics until now the first started with the Unix system talked about in and out of the Unix went through the the Unix networking then we looked at Perl programming in detail we went through all the aspects of Perl how the various variable specification what types of variables that Perl have then we went through like the data structure essentially and then we also looked at the control structure and then now we got proficient enough in Perl then we started looking at tickle tickle and TK initially we started with tickle again we went through the same exercise of the data structure control structures how to manipulate tickle and some of the variable substitution and the variable substitution with the dollar and we also had like some functional function substitutions basically that we looked at how to run function using the square brackets and finally we also looked at the TK essentially and then we looked at how the TK you can write widgets basically and then you can code all these graphical information what kind of graphical structures are supported by TK and then we also looked at some of the advanced concepts in tickle and then finally in the last few lectures we also covered some of the uniqueness with the synopsis tickle mainly the collections as one of the data types or data objects and how to manipulate the collections I hope like you remember all the things like the get some get commands essentially so I think like today we are going to switch gears again and then move to the next topic which is the Python programming so I will be talking about Python and then also we will be finishing up with this Python programming as the main more lecture so let us begin in earnest with the Python programming so what we will be talking about we have about 13 chapters that we will be going through first we look at some very basic stuff as to how to interact with Python how to do some simple commands things like that then we will go more into details the conditionals then we will look at the functions the Python functions then we will go through the iteration or the while loops and the for each loops and how to specify those things in Python and we will look at strings the collection data type which is introduced in the tickle programming but we will be looking into that then we will go through some advanced functions exception handling then we will cover the Python module so one thing is like why is this important we will come to know in a short while and then we will talk in more details later on then we will look at some of the Python files the documentation classes again this is another e topic why do we do this and then the CGA programming so these are the main topics that we will be covering in this section of the of our class so without too much so before we talk about all these things I want to make sure that the Python language is similar to Perl C and Java but it is only similar there are some definite differences between these languages also so initially I want to just give you some brief overview of what Python is and then we will go into more details before that some of the resources that you can look forward to so again there is learning Python by Mark Lutz and David Asher this is one of the books dive into Python mark pilgrim how to think like a computer scientist learning with Python is another one this is by Jeffrey Elkner Downey and the Smiles and then the programming in Python 3 is an introduction to Python language again you will be talking about this number 3 and then there will be also number 2 so what is the what is the significance of that we will talk about that and then finally like I mean this is a kind of a good reference basically that you you can always go back to which is the Python.org this provides you with if you are in doubt you can quickly go to this website and check the answer for your particular problems so the first question we ask is now we learned about Perl we learned about tickle why Python so Python is a high-level language and you can do a lot with relatively little code Perl you can see that basically it can get cumbersome tickle as you know like I mean it was developed as a quick scripting language but even in tickle programming tickle becomes quite cumbersome when it comes to complex systems so why Python it is also supposedly easier to learn than the main competitor Perl so it kind of replaces Perl with the more definite concepts I will explain to you those things in the Python nowadays is fairly popular among Tyler languages in fact some of the companies are built on Python for example Google Google people use Python more quite frequently and basically that is the main programming language and it has a robust support for scripts and also it is it has a robust support for object oriented programming so this is where like when we talk about classes and these things we will talk about that in the coming pictures and then it also supports integration with other programming on which so basically like if you have Perl and things like that some modules you can easily call from a Python language into those those modules okay so now we will be going into like the very basic stuff the very basic stuff involves running some few Python programs then we will go into the variables how to print so the printing itself and then some operators input how do we input objects into a Python program and how do we call comments and then scope the scope of the variables how to how they extend and even like scope of the program itself so we will take one by one so the Python programs basically like even we can run Python program from files just like Perl or shell scripts by typing Python followed by the program name dot by this by is basically the extension that we will be using I mean and in fact this is the short giveaway that it is a Python program the file can just contains just the Python commands essentially you can also like invoke the program directly by typing the name of file just program dot type if it has the first line the pointer to the Python installation so here the installation is Python so if you do like a hash bang user been Python and the first line in your script and then you followed by the Python commands then you can just simply type that particular filing and it will execute of course you need to set the execution permissions once you do that it will just execute so this is just like a shell script it works as long as the final form is the function as I mentioned then finally like I mean you can also enter Python shell and then the Python commands you can run Python commands interactively by typing Python so these are all like valid ways to do it so now so now let us see how to do an allow world program so here is what basically like I mean every programming language we have this hello world script so here the example is shown here we use the user been Python and then just simply say print in ports hello world again if you save this file into hello dot pi then you can execute the permission on the file basically like just do a change move you plus x hello pi in the unique window and then you can just run it as a lot of time when you run this program the output is here basically just since this statement hello world so this is simple enough I think I think you should be like now very familiar you should be confident to write for Python programs so now let us look at some more on the printing so here you say print hello and then you specify a comma and then x x star star 2 x star star 3 so what this means is essentially it is going to print this string or hello followed by whatever the value of x then the x power 2 which is x squared and then it prints x cube so here x is 4 so it printed 4 16 and 64 and then whenever we specify backslash t that is a tab character so then it actually like moves it by a tab amount and then prints the next one so if you say print 2 x 2 is equal to and then we import so this is not evaluated off the string and then here we just evaluate to power 2 algorithmically so the printing you can see now that you can mix and match things basically you can mix variables expressions with different types of variables so this is all like the flexibility that Python offers and if you end a print statement with a comma that suppresses the new line so that the next print statement starts at the same you can also print to an open file and basically like it is just like this out then I mean print and then double arrow say out file and then the message so the message will be printed there so now let us look at some more fun stuff so here we have another example the basics of pi so we specify the header actually like this should be Python is a bin Python then we say print 1 plus 3 and we say something like pi is 3.14 1.9 to 6 and we just a print pi we can also make a like a message and the message is a string hello world and then we can put print message so now the output of this particular run is going to be the first one is it is going to evaluate this expression and print the result which is for for the second one there is a print statement here this print pi and then it only going to replace this five with the actual value so this is the variable and then it replaces the variable and then finally the last one the print message is in the message will be replaced with its own value which is the string variable so you look at this basically you have a variable name which you never declared what type of variable is and then you also like a in print those things fairly easily so summarizing the previous example as you see like the pi and messages message are variables but one is actually a floating point number the other one is extreme and notice that we never declared these types in our example and Python itself decided what types of these variables so in Python actually the variables concept of variables are just just an object reference in this is also like we saw some of these kind of concepts in tickle as well when we talked about like these associative arrays and things like that there index and value or the index is basically just a placeholder this is just an object reference the reason we do not declare the types are because the reference might point to different type later on so there is one example x is 42 y is hello so print x y prints 42 hello print x, y but you can also change this type into like I mean actually like there is a statement another statement missing which is some y equal to x and then when you do print x y now it actually prints 42 and 42 because now it actually like now change the data type from the string back to this integer so you can actually like in midway you can change the type of the particular variable so again this is another key concept with Python so one thing that you can do is you can have so here is there is a function called we haven't introduced the function but let's say like I mean there is a function called type that determines what kind of type it is so here this define pi as 3.141.926 the message is defined as hello world and then I is an expression 2 plus 2 now if you ask Python to print the type of pi type of message and type of I you get this outputs basically the first one is a floating point number the second one is a string and so it does recognize all the types only thing is it is intelligent enough to figure out how to apply those steps and also when to apply what type so that is a very powerful concept so how do we define the variable names so the variable names can contain letters numbers and underscores but it has to begin with a letter and that is how Python identifies a variable name and it cannot be one of the reserved Python keywords here are some of the examples and as assert break class continue death be a LS else accept exec finally for from global if import in is lambda not or has print raise return try while with and in actually like I mean if you go to any of the websites that I mentioned earlier you should be able to find these reserved words the thing is basically you cannot use reserved words for a constant or variable or any other identifier name the identifier name basically or a variable name it is used to identify not only just a variable this these rules apply for function a class a module or any other object and the other thing is it is a Python also does not allow the punctuation characters such as the at symbol dollar or percentage within any identifies Python is a case sensitive programming language so that the upper case and the lower case of two different identifiers so now let us look at some more so any names starting with one underscore will be being underscore followed by like a letter they are not imported from the module import statement we will we will look at this one basically look this one later on as to how to use that and then names starting and ending with two underscores so underscore underscore be underscore underscore they are special basically they are system defined names the names beginning with two underscores but without any trialing trailing underscore they are local to a class so when you define a class the variables within the class follow this convention which is for two underscores followed by a name a single underscore by itself denotes the result of a last expression so this is again useful when we talk about functions because one of the things that gets returned is underscore if you do not specify a specific statement this is something that we saw in the tickle side basically so those are the console that are still continuing in the in Python so the key thing is basically the variables in Python they are nothing but reserved memory locations to store values this means that you can create a variable and you reserve some space in the memory that's all and based on the data type of variable the interpreter allocates memory and decides what can be stored in the reserve memory so you can store integers decimals or characters into these variables and icon variables do not have explicitly declared do not have to be explicitly declared to reserve memory space so this is what we saw in the earlier ones so now let us look at some of the operators so the standard operators basically that we all know of the plus sign for addition minus for subtraction division exponentiation we also have the start of or multiplication and then modulus basically which is a reminder after division and then we will talk about the comparison operators in chapter 2 one thing that I kind of talked about earlier basically this concept of simplification basically this is a very this is kind of the it is not a purely a scripting language but kind of a higher language which also enables you to program in lot of shortcuts so one particular shortcut probably like we will talk about this is this multiple assignment you can do something like a equal to be equal to C equal to 1 this is like a basically everything for sign for more you can also say a, b, c equal to 1, 2, 3 so everything is assigned once basically a so from 1 2 and C is assigned so we will talk about some of these things also coming slides so here is another example this is known as the operators Python so you know what 2 times 2 is so hence 4 now if you do a 2 star star 3 which is exponentiation the result is 8 and if you do a 10 modulo 3 the answer is 1 now if you print 1.0 divided by 2.0 this is something that we saw in the in tickle this is a floating point so the result is 0.5 but if you do 1 divided by 2 that is still treated as integers so the result is 0 so this is exactly the same that we saw in tickle as well so in that sense basically like the days like to go now Python is actually incorporated operators like plus equal to which is like a plus equal to be the same as a equal to a plus so it is like the self addition but the plus plus the increment or decrement operations they do not work in the Python so now let us look at some of the type conversions essentially any int float string boolean or converted to integer floating point string of boolean the boolean is essentially will have just true or false respectively so here type conversion routine if you do a print 1.0 by 2.0 the output is 0.5 print 1 divided by 2 they are integers so output is 0 you can also name specifically mention it is float 1 divided by float 2 and the result is 0.5 and now you can convert this floating point in the integers by simply operating upon an integer and then the result is the string and if you do a string the result is exactly the same because in string actually they do not have any basically just the reports and string now the boole function basically of 1 is true and then boole function of 0 is false now some of the things that we saw in tickle and that is still applicable in Perl for example this string multiply basically so if you have a string operator times 3 and then you can also use a plus operator or an addition operator on string and it just brings out so before we go into the next one I want to also talk about a lot of other things one is the numbers in Python the the data type is immutable this is a new term immutable data type what this means is the changing the value of that number data type results in a newly allocated object so if you change the value of the number data type results in a newly elected object numbers are immutable data type and number object is created when you are saying a value to any of the object and the Python supports four different numerical types we saw one of them in the previous one and it also supports long they are called the long integers essentially usually represented in actual or etc then float which we saw the previous example and then finally complex and then the complex is basically for complex now let us look at how do we gather input from the keyboard so for this we use this particular function raw input or we can also use this input so let us see like how we can make this so I equal to raw input enter the math expression and then we print I essentially so it says basically like enter the math expression and then we say like 3 plus 2 now the I value is the same 3 plus 2 doesn't do anything basically they poppy cinch into I now we say like day equal to input enter the same expression now if you enter the 3 plus 2 it is evaluated and then the result is shown as the value of day so we have like two ways of inputting value or a data from the keyboard one is the raw input and then the other one is input so the raw input just obvious whatever you type exactly as this into the take it takes it into the program whereas if you do just an input basically it evaluates the expression first and then push the result into the variable now how do we comment use the comment in Python it is very simple similar basically the hash sign is used as a comment and anything in a line after this hash symbol is still as a common so you can put anywhere the comment anywhere and it will just be treated as a comment from that point onwards in that this is just like the full so even in Perl we do exactly okay so so far what we have done is we just introduced the Python so we started with actually what why Python this I think you had understood that concept basically we talked about basic stuff which is how do we invoke a Python first of all we talked about the high level language how how we can write code or relatively less code and how we can write the code that are easier than Perl and also like I mean how it is popular basically Python is being used in several companies as the main programming environment it also supports object-orientedness which we will talk about in towards the end of Python but I want to induce you to the object-oriented programming concepts and then finally like it also allows integration with other languages now we also like talked about some of the things we wanted to see how to run Python programs or our variables how do we print those things and then some of the operators and input to the how do we input into the program into the Python and then the comments we haven't talked much about the scope you will see and talk about that now so for invoking the program the Python program essentially you can just type Python followed by Python program or the other method is basically like to put the pack to the Python then you can invoke it from there or the third method is basically just invoke a Python shell and run the Python commands interactively by just typing Python followed by Python so simple example hello world we saw this basically just say print and then it some of the other ones basically print like value of text x squared and x cube it is very easy basically hello and then it just prints exactly the same you can also print like the strings this is the whole thing is a string followed by a tab and then the actual expression so the expression expression will be evaluated and the value shown and we can also print the result or some any kind of message into a file by just using the double arrow and then the out file so we saw some of the variable types essentially like I mean can be a coding form in the string or or an integer and they also mentioned that you can have like multiple of them and then the variable type can actually change as I mentioned here where initially it was a string type and then the integer type by just doing assignment and then also mentioned that these variables are immutable types so and you know the definition and then the type basically type is the function that displays the type of variable so you can just say type I type message type I and then prints out each for each of them what is it then we saw the rules can rules for the variable names essentially contain letter numbers you can contain letters numbers and this course but it needs to begin with a letter and it cannot be any one of the reserved words in Python so those are the things that one thing that is basically like is another key element in Python that we didn't talk about is the intentation so the the lines and intentation are very crucial in Python so if you say like I mean if something true then print then we say else then another point so it knows that different levels hierarchy through this the the intentation so it is very very important to intend it your lines so that it doesn't you also saw like how to the some more rules for the variable names so single underscore essentially like I mean this is this is to show that they are not imported from the module import statement and then the the name is starting with double underscore that's a special or a system defining and if the names begin with this double underscore followed by the variable name without the trialing underscores then it is a local to a class so so within the class the variables that are specified are specified like this and then finally a single underscore itself denotes the result of the last expression so as I mentioned you can use it for functions to return values. Now we looked at operators some of the operators are simply the case so plus-minus division of the modelers and then so the comparison operators they will use in the next lecture. So here is just an example of all the operators essentially and you can go through it at your leisure you can see like how they get translated and what is the for each of these expressions the key difference is here basically how do you do the floating coin division versus the normal division and if you use this thing basically again you want to make sure that your answer is correct and then it has this plus equal to operator which is combining the assignment and then the action operator but it does not have an increment or a keeping type of completion. On the string data type the Python can accept a single code or a double code or even a triple code and follow put around a quadruple code to denote strings string literals as long as the same type of code starts and ends the string the triple code is usually used for strings that go across multiple lines so if you want to stand across the string multiple lines then you can use the triple codes and a single code essentially it is also legal syntax and then we looked at how do we do an operations on strings like this v times 3 becomes an any me or hello plus word becomes hello world and if you want to input from a keyboard the raw input basically and the input are the two functions available so the raw input actually gets whatever is there as is and then as the math expression will try to evaluate an expression that is what gives the input value so if you use input then this mathematical expressions evaluated use raw input then it is not evaluated then we looked at the comments we know that anything after the hash symbol is treated as a comment it is just like per so I think we will actually I think like we covered most of the the things that we said we will be covering except the scope of the variables we will talk about the scope in the next lecture of the extent to which the variable names can be and be available so that is something that we will talk about in the next lecture okay thank you very much