 So, good morning everyone. So, we will start with basic python in earnest. Let us get started straight away. So, here is an outline of what I will be covering today. I hope to go through this and some additional material, but let us see how far we go because it depends on how much you are able to absorb in one day. It is a fair bit of material. So, we look first at the language itself very briefly. I do not want to spend too much time and then we will go over the basics. We look at the interpreter, basic data types and operators, strings, conditionals and once we start hitting loops and list IO files, functions, tuples, dictionaries and sets, I will slow down. But the initial parts I will try to keep a good pace. Hopefully by lunch time we should finish, it will say lists. I would be happy if we get that far. So, let us move on. Let us get to the language. So, why do we pick python? Python itself unlike say MATLAB or equivalent languages, python is a full fledged programming language. It is not just designed for numerical computing. So, as a result if you learn python or our belief is that if a student learns python, they are equipped to deal with a larger set of problems than is necessary, than is possible with something like MATLAB. The reason is if you look at most research and use of a computer, the use is not always restricted to numerical computing. You will need to use it to do a variety of tasks. So, the point is if you are to teach one language, we would rather teach one language that is capable of handling a variety of tasks rather than teach you five different languages that do different things in different fashions. So, python is an extremely powerful and high level language, which basically means it gives you a lot of powerful constructs that are at a much higher level than say a lower level language like FORTRAN or C, which means with a lot less code, you are able to do a lot more work. Python is also interpreted and some of you might initially think why I mean an interpreted language is going to be slow. Yes, however the advantages that an interpreted language bring are that it is much easier to develop and much much easier to do rapid prototyping of ideas. And now with computers being this as fast as they are, it is very important that the developer gets more feedback and it is much easier on the developer than absolute performance. Python also has a very elegant and very readable syntax. So, basically as you will go through this course, you will see that python programs are very easy to read and part of the reason is that indentation is forced. So, the block structure of a python program is determined completely by indentation. And therefore, it is a lot easier to read for everybody that the code looks pretty much the same. Unlike in C where you can use brackets and basically the appearance, visual appearance of the code is could be different for different programmers in this case it is not. It also provides a huge number of or a very large number of high level data structures that are extremely efficient and extremely powerful. In addition, as you will see over the course of today and maybe the future classes, Python is very easy to learn and as a result of all the above features, it allows you to concentrate on the problem instead of the language. So, if you look at more complicated languages like say C++, you will typically need to have a copy of the language reference or you will have a copy of some good book on the programming language with python that is not the case. I have been programming for many years and all I have been, all I learnt was from online documentation say the tutorial and the rest I do on the interpreter. So, if I have to learn and explore something, I will use the interpreter to do it. As a result of this python offers increased productivity which means you are able to do a lot more and a lot less time. The creator of the language is Vido van Rossum. He is a Dutchman. He is currently in the US and he works for Google. He is called the benevolent dictator for life. So, the BDFL term means benevolent dictator for life. In terms of the language he is, he basically makes most of the important decisions for the language. And it was python the language was created in 1989 and do not get confused about the origin of the name python. The name python does not come from the reptile python, but it comes from a comedy, 70s comedy called the multi python flying circle. So, continuing on in addition to being an extremely powerful programming language as I had mentioned before the language is very readable, but one very important and often neglected fact is the important fact that python is interactive. So, as I will go along in this course you will see that very often I will switch to an interactive interpreter the python shell and show you how you can actually write nice bit bits of python code there test your ideas and then develop your code. So, basically this offers you a very fast what is called the edit test debug cycle. So, if you run into a if you write code it becomes much easier for you to quickly test your code and debug the errors on that code. And as I mentioned in the last slide it does the language does not get in your way. So, you do not have to struggle with how do I do this in this programming language instead you are more concerned about how do I solve the problem which is really what you want from a good programming language. It also handles basic the memory management for you. So, you do not have to deal with pointers which are usually the most difficult part of any lower level programming language. In addition to this python has a huge standard library a very significant and large standard library. So, if you go to the python.org website and look at their documentation there is a document there called the library reference and repeat the library reference it has a listing of all of the standard library packages that python offers. And these packages are very varied. So, you can do things like access the internet send email parse HTML parse XML do system level commands access zip files create zip files or create tar files do shell like scripting all of that stuff is built in as part of the language as part of the support structure that comes with the language. And these are called the standard library. So, the standard library has a lot of functionality available by default inside it. Therefore, as a result of the combination of very good easy to learn elegant powerful programming language plus the standard library allows you to do a lot of things with python itself. Python is also object oriented. However, it does not force the object orientation on you like for example, java does. So, if you want to write a purely procedural program you can certainly do so. But if you want to write something you want to extend you want to create your own data types then you can also do it in python and there is no problem with that. So, it is kind of a flexible language that suits your needs rather than forces you to do anything that in a particular way that it desires. The other important point for many people who are doing engineering and science is that often they have their own codes they have C C plus plus and fortran codes. And python offers a lot of techniques and strategies in order to be able to access such codes and be able to in order to be able to use all of this code. So, one of you has asked me a question as to how it does handle memory management well it uses reference counting to handle memory management. And basically what you need to think about with respect to memory management is do not worry about it. You create objects and python will manage these objects for you you do not have to worry about it at all. Ultimately the point of this whole thing is that your time that is developer time is a lot more valuable than machine time. Because nowadays computers are much more powerful than they ever used to be and they are rather inexpensive. So, let us get started let us look at the interpreter. So, to get started the first thing you do is on your terminal I am sure all of you know how to start a terminal. You start the terminal and you will see text that looks like this. So, if I start the python interpreter on the shell you will get something that looks like this. Here we are running python 2.6.5 if you notice here ok. So, basically once you start python I am sure you must have all started python you can you will see this text that starts up which tells you about the python version that you are running and you will get a prompt with these three arrows which is the interpreter's prompt. And the interpreter is basically waiting for you to give it some command input. So, let us get started with the first. So, let us write our first little python program. Let us say print hello world typing here something else here and you hit return. So, type out this text hit return and the interpreter will print out hello world. So, to exit the interpreter you hit you press control D and then you exit. So, to repeat you start with typing python hit control D to get out of the interpreter. This standard python interpreter that we have we call it the vanilla python interpreter is not the most full featured and functional. And there is a special interpreter called I python which is again implemented fully in python and I python is what we call an enhanced python interpreter. And what I python lets you do is it gives you a lot of user conveniences that are extremely convenient for a programmer. So, what we will do is we will soon switch over to I python. But before we move there let us look at the versions. So, someone yesterday even asked me what is the difference between the live python that we have supplied and 3.x. In live python what we have by default provided is the 2.6 or 2.7 version of python and 3.x is basically not backward compatible with 2.x. So, there are some changes to the language that have been made in order to improve the language. The problem however 3.x is a lot of the scientific packages that are necessary for the purposes of this course and for the purposes of engineers and scientists are not yet converted to 3.0 3.x. Therefore, we are continuing to use 2.x for the purposes of this course. Now 3.x introduces some changes, but the changes are not too major. And therefore, what you are learning in this course for the most part will work well in 3.x once all of the packages are ported and you need not worry about it too much. Just continue to use 2.6 or 2.7 in the future and maybe in a year or so when things mature in the 3.x side we will move to 3.x. So, let us start with I python now. So, I python is an enhanced interpreter and to be able to use it you need to have it installed. So, it does not part of the standard python ecosystem. So, you have to install it, but to run it once you have it installed. So, you have installed the live DVD that we have given you it comes built in with I python. So, if you say I python it will start what is called the I python interpreter session. So, what you see here is again something similar to what we had before the string that tells you about python. In addition it says that you are at I python 0.10 and it says it is an enhanced in an interactive python. So, let us start with our first program in python print hello world and it does the same thing as python does. Notice the differences the differences are that instead of the original prompt of the 3 less or greater than arrows you have this in number 1 and notice that the prompts are numbered. So, you know in 1 in 2. So, each of them has a numbering in our slides we have we have ignored this number because it makes it little complicated. So, you will only see in open bracket close bracket colon. To exit I python again you do control D at this time python I python will prompt you it will say you want to exit really or not. So, if you hit return or you press Y and return it will exit if you press no obviously it will not exit. So, to repeat you start I python just like python you just spell I python and you hit return you will get the I python prompt and it is like the standard I python standard python printer except it has some additional features and to exit again you do control D. If you are running on windows you will have to do control Z followed by a return if you want to exit the I python session. So, let us get started we will start with some simple math to get comfortable you can use I python as a simple calculator and I do this very often. So, if I want to do some little calculation I will quickly open up an I python session and then start typing away to get the answer. So, let us try some simple tricks. So, please type the expressions that are given to you on the screen here. So, each time you run one of these lines say 1 plus 2 and you hit return you will get the answer. So, you will get 1 plus 2 the answer will be 3 same way if I say 5 minus 3 I get 2 7 minus 4 and note that if I keep hitting return the counter just keeps incrementing they just blank lines 6 into 5. So, notice one thing that every time there is something that is returned by an expression. So, if you look at 5 minus 3 it is an expression whose value evaluates to 2 all of these evaluations on the values that you get are stored in something called out. So, you look at it there is an input which is clearly marked by i n and there is an output that is clearly marked by 3. So, the third output is 2 the fourth output is 3 and so on. So, you can see that it is already doing something that is reasonably useful. One very powerful feature of I python is the fact that it lets you access the I python history. So, let us say if I do print 1 plus 2, notice by the way that when I made a mistake I said print 1 plus and I accidentally hit return it gave me a syntax error it did not bomb that is it did not die and the I python session did not kill me I just got an error telling me that there is an invalid syntax this is one of the nice advantages of an interactive interpreter or an interactive session. Anyway, so once I print 1 plus 2 and hit return note that it does not give me an output because the print basically prints it to screen it is not evaluating or returning any value. If I did 1 plus 2 just to recap it actually gave me an out on the other hand when I do print it does not give me any output. But what I am trying to illustrate here is the feature that I python offers. So, press up arrow now and you will get 1 plus 2 press up arrow again and you get print 1 plus 2. So, I want you to do this exercise change the that line print 1 plus 2 by hitting up arrow go to the previous command and change it to print 10 into 2. Please do this on your sessions I will give you say 10 seconds to do it. So, if you have any questions now please raise your hands. What is the reason for not showing out is one of the questions any other questions to answer your question what do you think print does print return print something to screen it does not. So, it is not returning a value it is not evaluating an expression it is just printing some value to screen. So, it is not it is not it is not like 1 plus 2 1 plus 2 is an is an expression that is being evaluated to 3 whereas print 1 plus 2 is explicitly telling python print that on screen. You are not actually evaluating while you are evaluating it and the evaluation is passed on to print and you are telling print to do something and print does not do anything apart from printing it to screen. So, there is no output that it actually produces apart from writing to the screen that you have already seen that is the reason why it does not show it. Since no one else has any questions let us move on quickly. The other very very powerful feature that I python has is what is called tab completion. Yes as I explained printing is after the evaluating an expression, but you are essentially telling python I want to print that expression you are not telling it to evaluate the expression and return it. Remember that you are composing functions you are saying that print you are saying print is a keyword. So, you are saying print something and you are explicitly saying you are giving the expression to print not to the not to the interpreter. So, if you want to see something on screen you are going to have to print it. I python is doing or python is doing a simple convenience for you that it is actually giving you the output of every expression that it evaluates and it caches and stores that somewhere. So, do not get too worried about it, but realize understand that print is not going to evaluate anything print print is going to show something on screen. So, you have evaluated an expression 1 plus 2 and it is going to be sent to print and print is going to display it that is it. And if you want to see it on screen say in a python script or something like that you have to print it if you do not print it nothing will happen. The python shell or the interpreter is conveniently showing you what has been evaluated that is all. So, one powerful feature that is the fact that python provides you tab completion. So, to check this out. So, let us type r o tab and you get round it automatically completes r o tab to round. So, try to type r tab and you will see that it will actually give you all of the possible completions that are available. So, if I say r a tab it will now give me 3 options say r a n becomes r a n g range. This is again very powerful. The other extremely useful functionality that I python provides is the question mark for help. So, let us say I have the function a b s. So, I do a tab a b s I get if I do a b s question mark and followed by a return it will show me the help built in help for the function. So, for example, if I do a b s of 19 what it is saying is it returns the absolute value of the argument. So, if I say a b s of say 9 it is going to be 9 a b s of minus 9 it is going to be 9. So, now, you can look at the documentation of built in functions and decide for yourself what you need to do. So, one note for all of you please ask questions relevant to the section we have 107 slides that are going to cover a lot of material. So, please do not jump ahead and start asking me questions I will not answer such questions. So, now, if you look at the round documentation. So, round documentation how would we look at that we will have to do question mark followed by return. When you do that it is going to say round give you a number and now it adds these funny looking brackets here again those of you who are already familiar with this please do not say there is nothing new in this or something like that I am trying to explain the language for the purposes of everyone who is attending and there is a lot of people who are attending round number followed by optional parenthesis in digits suggest that the end digits that you see here is an optional parameter which means I can do round 1.123 and that round number is it to 1 decimal place, but if I say round it I supply an additional argument which is optional to say 3 decimal places or 2 decimal places and notice that in all of these cases when I do when I wanted to change the line I hit up arrow and change. So, it is a good idea to be lazy when you are doing program. So, is this clear any questions at this point for optional arguments. So, documentation strings will generally use these optional into denote optional arguments will use square brackets. So, the other thing that could happen is sometimes you are typing you say round 1.123 and you accidentally hit return like this. Now, you will see that the prompt has shifted to dot dot dot colon what this is suggesting is I Python is expecting additional input that it is not complete. So, now you have two options one is you hit you complete the bracket you get the result or you can hit control C which will basically interrupt it and not evaluate what you have typed. Generally, hitting control C is one mechanism by which you can interrupt. So, if you have say a loop that is going off it is going crazy you can basically hit control C to interrupt it. Someone is asking me a question we are getting different answer yes. So, someone has asked me this nice question it is a good question. So, you are saying round 2.626 comma 2 and notice that it is saying it is 2.62999999. So, what do you think the correct answer? So, in my case I would think the correct answer is it should be 2.63. So, if it is 2.63 2.629999 is the closest floating point representation that you can get. So, when we do numbers later on you will understand why this happens. So, we will do this in a little while. So, let us move on to basic data types and operators that are available in Python. So, the basic data types that are available are numbers which are integers, floating point numbers, complex numbers and all of these are built in. There is also the Boolean data type and there are sequences. Sequences most commonly are strings, lists and tuple. So, a string is a sequence of characters, a list is a sequence of objects and so is a tuple. We will look at these in greater detail as we move on. So, some of you are running into issues with different versions of Python that you are running. So, sometimes the results could be slightly different. For example, the way in which quantities are printed in 2.7 Python version is very slightly different from the way in which numbers are printed on screen. On screen for example, when you look at my interpreter I am getting 2.629999. So, if you are using a 2.7 interpreter it will probably give you 2.63. Now, there is nothing correct or wrong about it. In which case it depends the actual what you are seeing on screen depends really on the implementation of that particular version of Python. Now, I will get to floating point numbers in a little while and we will discuss all of this in a greater detail when we do floating point numbers. So, there is another question which says is Python not a typing language. I do not know what you mean, but if you mean that is Python strongly typed the answer is yes, Python is strongly typed. Every object in Python has a type, but it is not statically typed, it is dynamically typed. So, let us move on. We will look at little more. So, please bear with me for a little while. Please do not ask me too many questions for the first phase. Let us finish the basic data types and then we will then please I will stop you ask me a bunch of questions. So, take down a list of questions because I want to finish this segment and we will answer some of your basic questions initially. And once I do that we will get somewhere where we will have comfortable point where we can ask things. Yes, I will do that. I will take questions after some point, but people are asking me and sometimes I prefer an interactive class to a non-interactive class. So, what I will do is I am going to wait till I finish basic data types and operators and then I will pause for about 15 minutes to ask for questions. So, please till then I will not you can go ahead and type the questions here if you want to, but I would suggest you do not because I look at the chat session to know if someone is having a big problem because I see it show up for me. So, if someone has a question something urgent you please ask me till then I would suggest you either take it down write it in a separate terminal or something like that. Thank you. So, let us move on. So, if you want to create a variable so far we have not done that all you need to do is give it a variable name. There are certain restrictions on variable names which I am not going to discuss right now. So, if you want to create an integer say you just have to say a is say 13. Now the type of a can be determined by the command type of a and the type command if you want to find out what it does the type function basically returns the objects type. So, if you look at the documentation again it says type given any object will tell you the types objects type it will return the objects type. So, it is a built-in function. So, it is a python built-in function that is available for use. Now integers can actually be arbitrarily long. So, for example I can know it turns out that I am actually lying python has two forms of integers one is the integer which is a fixed size the other is what is called a long, but you do not have to worry about the difference. For example, so if I say type of a gives me a variant if I say type of b it will tell me it is a long. However, obviously I can say c is say a to the power a. So, what do you think the type of c will be? Remember what is a? a is 13, 13 to the power 13 is going to be a very large number. So, type of c is actually long. So, because what happens is automatically it overflows and python will convert that integer to a long internally. So, you do not have to worry about. So, effectively all you need to know is integers support or can be arbitrarily long. So, you can even do. So, if I want to do say c to the power 3 or c to the power 4, c to the power 5 as you can see the integer can keep growing in size. So, it is not to a fixed size. Same point numbers in python are again pretty straightforward. So, if I do 3.1415 type p it will tell me it is a float. Notice that on different interpreters you will get different numbers when I do p if I do just p here look at the fact that it shows me so many decimal places. However, if you are using 2.7 it will only show you 3.1415. So, decimal numbers are basically represented using the float data type and the float data type is a finite precision data type. So, basically it is a 64 bit I triple E 854 standard double precision number. So, float basically corresponds python float corresponds roughly to c is double. So, they have a fixed precision. In fact, they have a fixed amount of space for the mantissa a fixed amount for the exponent and they have a sign bit. Now, as a result of this it is obvious that you cannot express every number in the real line with floating point numbers. So, what happens is in my case if you look at p when I type p here it prints 3.14150002 the reason is there is no exact representation of 3.1415 on the computer. So, it is giving me the nearest possible expression that it is able to derive based on the binary representation that is stored inside. And this is just a natural issue with floating point numbers that you are going to have them regardless of what you do. So, basically it makes sense only to print out say the first 4 digits 4 or 5 digits in this particular example. So, to summarize floating point numbers have a fixed amount of precision floating point numbers correspond to c floats they are not arbitrary precision they are essentially 64 bit numbers 64 bit floating point numbers corresponding to the I triple E I think 754 or 854 standard. And as a result of the fact that it is a floating point number it cannot represent every real number exactly it is only going to be an approximation. However, the approximation can get as close as you would like given the limitations of the floating point number. I hope that answers some of the other questions people were having just before. So, floating point numbers are again built in into Python. So, to create one you simply do c is let us say 3 plus 4j type of c is complex to access the real part you do c dot real, c dot image and the absolute of c will give me 5 it is a square root of the sum of the squares of the real and imaginary part of the complex number. So, some of you might have the question. So, is j a keyword turns out that j is special syntax. So, when I do c is 3 plus 4j it does not mean that j is a variable that is available. For example, I could say j is 1 and c is 3 plus 4j will still give me 3 is a complex number and j is still that integer that has been created. So, j is simply special syntax that is used by the interpreter to allow you to create a complex number. Another way by which you can create a complex number is to say complex. So, you can do it either by this convenient syntax or you can do it by this. So, moving on you can perform operations on numbers. So, the first 3 examples you have already seen 23 plus 74, 23 plus 23 minus 56, 45 into 76 and here comes the first big surprise. So, if you do 8 by 3 you get 2. So, when you divide if you are doing division of two integers it will assume that you want an integer result. So, if you want explicitly a result that is a floating point you must cast one of the numbers into a floating point. You could either do that or if you have a variable say you have a is equal to 8 and b is equal to 3 and I say c is equal to a by b c is 2. However, if I wanted to make this such that I explicitly wanted to make this a floating point I can do this. So, there are different ways by which this can be achieved. The thing I wanted to note bring to your attention is if you look at the terminal earlier on I had said a is something I had said a is some 1 or something like that. Later on I said c is 3 plus 4 j after that I say c is a floating point number. So, as you can see a variables type is not fixed forever in time. A variable can acquire a different type of object at any point of time and you control what you supply to it. So, this means that the objects are the names are actually bound dynamically to different kinds of objects. It is not statically defined as it could be in a statically type language like say c or c plus plus or java. So, moving on the other functions that are of interest are modulo. So, 87 percentage. So, the percentage operator is modulo and the power exponentiation operator is given by double star. Note that if you do 7 power 6 doing this will give you a very surprising answer. Doing 7 karat 6 actually does a bit wise operator. So, do not get confused the karat is only a bit wise operator and power is always given by double star. Notice that this slide is again just telling you what I have already shown you that all of the operations that I did could also be done as well on variables. So, you could say a is 23, b is 74 and a star b will give you the corresponding result. Similarly, c is 8, d is 8.0, f is c by 3 all of this again things that I have already shown you on the interpreter. So, in this all of these cases c is equal to 8, d is equal to 8.0 all of those cases show assignment. There are also in place assignments. So, for example, if c is equal to 8. So, c slash equal to 3 will be c is equal to c by 3. So, it will be 2 in this case. So, if I wanted to change it to a floating point number. So, now c will be 2.666. So, it is very straight forward. So, I am going to move on because this is very straight forward material. Let us move on to Booleans. So, for Boolean operations there are two basic quantities true and false. So, to define something as true you use the upper case true, little true is not defined. There is capital true is true. So, it is called true and not true is false. So, you can use to say something is true or false you use capital T for a small true and capital F false. The operators that you have operations on Booleans that you have are not please do not use something like this because that again does not quite denote Boolean operations. It will do bitwise operations. It will not every bit in some number for example or an and again all of these make it rather easy to read. So, for example, if you want to have a Boolean expression which says F and T or T it reads very naturally which is why another reason why Python is a lot easier to read for many people. So, notice in this case that I am using brackets here to denote operator of precedence. There is so I explicitly state what we mean by using brackets and this is generally a very good idea to do. And I am not going to discuss operator of precedence because it is kind of pointless. Even I do not remember half the time what is the operator of precedence in certain things. I can guess what is it. I can think of something but it does not really matter because always what you should be really concerned as a programmer is to make things readable to another programmer and not have to rely on some complex set of rules that someone has to remember in his mind. So, it is a good idea to generally use a parenthesis to denote explicitly what you try to mean and you can use as many parenthesis as you feel necessary for that particular expression. The other thing you should be worried about is do not use too many parenthesis. Then it becomes so many parenthesis that you cannot figure out what is happened. It is just a general point of style. So, moving on let us look at sequences. We will do the sequences in much greater detail in a little while. So, right now what we look at is the general flavor of sequences. What does a sequence? What kind of sequences are there? What can you expect from sequences? What are the most common operations that you would do on sequences? And that is what we will discuss right now. So, hold off any detailed questions of how do you manipulate strings? How do you manipulate lists or tuples? We will do all of that later. So, right now we will look at the big picture so that you get an overall perspective of the basic data types that Python has to offer, some of the basic data types that Python has to offer. So, the basic principle for a sequence is that it holds a bunch of elements. Sometimes the elements can be this have to be the same type. Sometimes they can be a different type. Elements are accessed based on their position in the sequence. So, the sequence is basically very efficient for random access which means I can access a sequence, any element of that sequence in constant time and they all have a position that is implicit in that particular sequence. I will give you examples to explain. And the basic sequence types that we are going to cover right now are strings, the type for which is str, lists and tuples. We will look at all of these shortly. So, here are 3 examples each creating a different sequence type. The first is what is called a string. So, let us just type this. Then you have num list which is a list of 1, 2, notice how it is created. A string is created with an open quote, close quote double quotation and a list is created with square brackets with elements separated by commas as you can see in this. So, square bracket open elements separated by commas close bracket. And a tuple is similar to a list, but it starts with an parenthesis 1, elements followed by spaces sorry by commas. The spaces are optional, the spaces that I am typing after the comma here or before the comma, they are all optional. However, they are important in terms of readability. So, it is a good idea to keep them. So, now I have created 3 variables grid string, num list, num tuple each of which can be created like this. So, now what can you do with this? To access the elements, the first major thing you will need to do is to access the elements, to access them, you basically can access them using the bracket operator. So, in this case if you do num list 2 or num tuple 2 or grid string 2, notice that the pattern is similar. That is the point that we are trying to illustrate. We are trying to give you the big picture. In the big picture if you want to access a list, an element from the list, you give it the bracket and you give it the index of the quantity. It turns out that in python the indices start from 0, they do not start from 1. So, num list 2 should give me what, think about it for a second. Num list 2 should give me what, it should give me 3. It will give me the third element in the list. Similarly, num tuple will also do the same thing. Like any reasonable language, all of the indices are based on 0, not on 1. It is not like strings are 1 and lists and tuples are 2. One of the things that you will notice with python is many things as you go along will become, will make sense and will kind of be the obvious thing to do in that particular language. The only thing different may be from Fortran is the fact that the indices are offset from 0 and not from 1. That is the only thing you need to remember. Now, given 2 sequences, you can add 2 sequences to form a new sequence. You are not going to change num list in this case. You are going to create a new sequence which is the sum of num list plus 3, 4, 5, 6. So, in this case what do you expect to see? You will get a new list which for whose the content are 1, 2, 3, 4, 5, 6, 7, 8, comma 3, 4, 5, 6. So, you will have a list of 1, 2, 3, 4, 5, 6, 7, 8 plus 1, 2, 3, 4, 12 elements. So, you will get a list of 12 elements. So, let us try that num list plus 5, 6. Now, how do you find the length of such a sequence? So, I will show you a little convenient trick. In the last case, I did not save the in this in this interpreter session. I said num list plus 3, 4, 5, 6. Now, I have lost that the thing that it evaluated to. I do not have that I did not store it as a variable. So, if I want it on the interpreter, the last expression is always available as underscore. So, if I say length of underscore. So, I could say for example, result is underscore. Now, I can say length of result and it is 12 as I had expected. Underscore is just a neat trick I am teaching you. It is not in the slides, but it is convenient sometimes. So, for any sequence, three things. You can access the elements using the bracket operator. You must give it an index. The index has to be an integer and it starts from 0. You will learn soon that there are negative indices that you can supply. We will do that subsequently when we do sequences in more detail. But it has to be an integer. The index starts from 0. So, the counting starts from 0. You can add two sequences of the same type. Obviously, it makes no sense to add a string to a num list. So, how do you know that you cannot do it? Well, we can try it. What do you expect? You will get an error. So, it says type error. You can only concatenate a list, not a string to a list. So, the error messages in Python are very, very clear. And I urge you to strongly ensure that you learn to read error messages. They are extremely important and many, many users, even people who are familiar with Python, who are familiar with programming often do not bother to read error messages. Error messages are there for a reason. They are for you to read and they are very precise. Typically, they give you good idea of what is going on. So, when you see an error message, do not just glaze your eyes over. Make sure that you read it and make sure that you try to at least attempt to understand what it is saying. And this is a very good practice for you, so that you are able to debug your own programs. If you see an error, you get a very clear understanding. So, what is it saying? It is saying a type error. It basically means the error has something to do with the types of the objects. Number two, it is telling you explicitly that it can only concatenate a list, but not a string to a list. So, given two lists, I could add them, but given two different types, you cannot add them. You may not be able to add them. Sometimes you can, sometimes you cannot. But by default, you should assume that you cannot unless there is a very obvious way that which they could be added. In this case, there is none. Finally, the last point is the length. So, if I say length of greet string, notice that I do not have to type all of greet string. I can do greet gr tab and it will, python will complete. So, python will complete on variable names and functions and anything that is available on your interpreter. So, tab completion is a useful thing to use as is history. So, length of greet string is 5. In my case, because greet string is hello. In the example that is given in the slides, the length will be slightly different. So, I hope you understand what is happening. So, the next major thing about sequences is the fact that there are certain common ways by which you can interact or program with these sequences. The first is checking for container ship. So, if I want to see if the number 3 is in the lists, in the elements of the list, I simply say 3 in known list. Same way, if I want to say if the character h is in the greet string. So, let us try some simple experiments. So, h in greet str. So, what do you expect in this case? If I am doing a check, it means the result should be a boolean. So, if I did this, what do you think I will get? I should get true. So, for example, if I did z in greet string, it should give me false. So, what if, does this also work for h e? Remember that my greet string is hello. Does this make sense? So, the first question you have to ask is h e in greet string. Is that a reasonable question to ask? The answer is yes. So, h e in greet string, it is certainly there and it should give me true. So, now, if I say 3 in known list, that is true. But can I do this? So, now the question that you must ask yourself is, is there an unambiguous way for python to determine what the user is trying to do? So, in this case, it turns out that 3 and 4 is not in known list. So, what do you think is happening? What is known list? So, 3 and 4 are there. So, why are you surprised? Well, what you are actually asking is, is this element 3 comma 4 in known list? It turns out that list can store anything, list can store other lists. So, if I say l is 1, 2 and 3. So, what is 3 comma 4 given in as a list? So, remember a list can contain other lists. So, now if I try 3 comma 4 in l, it is true. Do you understand? So, when I say something is in a list, you have to be very careful. You are essentially asking, is that element there in that list? Whereas, this does not hold for sequences which are strings, because in strings it is unambiguous. When I say he in greed string, what do I mean? Is that substring he available in this string? So, it is very clear, it is very obvious to the programmer. And in this case, again you should not be surprised, because this there is an ambiguity. Should I check for both 3 and 4 in that list or should I check for 3, 4 in a list? That is in this list. So, it obviously means that 3 comma 4 in known list, I would want to check for this because I can have 3 comma 4 as an element in that list. So, keep these small differences in mind as you program. One very useful tip that I am going to give you now, that you may not appreciate that I am telling you now, but as you program you will appreciate is to please use the interpreter more and more. So, if you have a question, should this work like this or should this work like that? What will be what is Python going to do? Do not ask me, ask your interpreter. So, you just start up the interpreter, type in the expression you are trying to experiment with, understand what it does, figure out why it is doing what it is doing and that will give you the answer. I can be wrong, but your Python interpreter is not going to be wrong because that is the interpreter. So, we now have seen how to look at, how to access the elements, how to add sequences, get the length of a sequence. This length function is a built-in. So, it is always available in Python. The check for container ship, you can do 3 or whatever element you are looking for, in is a keyword, the necessary list and this applies to all types of sequences. To find the maximum and minimum, you can say max of, there is 8 as you would expect, but what is minimum of grid string E? So, now it is going to do some kind of alphabetical listing and which is the smallest element in the grid string. Slicing, which is described in this third point, bullet point here, is an extremely important aspect of sequences. We will do this in much greater detail as we do sequences in more detail, but I want you to understand that there is this fundamental operator that you can apply to any sequence and it is called a slice. So, notice the next line, num underscore list, open square bracket 1 colon 5. The important thing for you to notice is, there is this 1 colon 5 here. Earlier the last slide, we simply had a single integer, but now you have this funny syntax of this 1 integer followed by a colon followed by another integer. So, what does this mean? So, let us see. So, as I said before, how do you find out what something does? Well, you type it, num list 1 colon 5. What would you expect? You would expect a slice to basically say, give me all the elements between 1 to 5, which is what it does. So, original num list is 1, 2, 3, 4, 5, 6, 7, 8. 1 to 5 is basically giving me element number 1, which is 2, element number 2, which is 3, element number 3, which is 4, element number 4, which is 5. And notice that it does not give you the fifth index. What is num list 5? Num list 5 is 6. So, it is not giving me that element. So, the general syntax that you should understand is, when you slice over a sequence, it will give you the starting index value, that is the first index, to every element excluding the last index. So, it will give me 1, 2, 3, 4. Is this clear? So, this is what a slice is, and it is an extremely powerful way. So, for example, if I want to get greet string, I want to get that is only a low. So, you can understand that this works for all kind of sequences, for tuples or lists or strings. So, these are common operations that are very important for you to understand. The last point that you will again, we will again revisit several times in this course is what is called striding. Notice that when I did 1, 5, the indices that I was interested on were 1, 2, 3 and 4. So, which gave me num list first, index number 1, index number 2, 3 and 4, which gave me the result 2, 3, 4, 5. So, I am striding there between those indices by one element. So, 1, 2, 3, 4. But if I want to jump the intermediate fellow, what do I do? I want to say give me 1, give me 3 and give me 5, but 5 is beyond 4. So, I want to just get 1 and 3, I could say num list 1, 5, 2. This will simply give me 2, 4. Is this clear? What it is doing is, it is giving me elements between 1, 2, 3, 4, but stepping by 2. So, it is essentially start index, last index plus 1 and 2 is jump by step by soming. So, if I did 1, 5, 3, what do you expect? It should give me 2, 5. If I did 1 and 4, it will simply give me 2, because by stepping by 1, I have exceeded my last index. So, I will recap all of these. Sending elements is through the bracket operator. Indices start from 0. You can add two sequences of the same type, that is very important. You can find the length of a sequence using the LEN built-in. You can check for container ship using the IN keyword. There are built-ins available to find the maximum and minimum element. Now, obviously these are only going to apply or make sense if you have elements of the same type and there is a notion of comparison between those elements. If there is no notion of comparison, you are finished. It is not going to work. You can slice a sequence using this syntax, which is starting index colon final index plus 1. So, why is it doing final index plus 1 and does not give you that last index? The reason is to do with supposing I have noom 1 colon 5. How do I get the remainder? I will do noom 5 colon. So, this will give me everything from 1 till the end. So, notice that if I do not supply an index, it means go to the end. If I just give a colon, it means from fifth to the end. Finally, striding, if you supply an additional colon 2, it will stride by 2. Colon 3 will stride by 3. So, with this we finish the basic introduction and now we will go on to string. So, at this point I will stop for some questions. So, please ask your questions, raise your hand or ask your questions and we will take a quick round of questions maybe for 5 or 10 minutes. I think there is a break at 11 o'clock. So, before the break 5 minutes we will ask questions. So, first question is what is the difference between a list and a tuple? We will answer that when we do lists and tuples later on. I will not answer that question now. The second question on the chat is if alphabets are capital and small in the same string then how does min max function determine the output? Please try this as an exercise for yourself and answer the question by yourself. You have the interpreter to give you. Third question is what is the use of ABS in complex number? Well, for that you need to understand complex numbers and this is not a class on complex analysis. So, ABS in complex number in complex number system, the absolute value of a complex number is defined as the square root of, so if you have a number A plus J B that is real part A, complex part B the absolute magnitude of that number is defined as square root of A square plus B square. So, think of it as a definition and ABS simply does that. Yes, so there was one question by VP COE Baramati. I will switch over. Yes, yes please ask your question. Sir, my question is when you told that when we are using print space 1, 2, 3, 4, 5, 4 plus 2, so in that case it is not going to show out. Yes. But when we are using the another functions like ABS or the round, so at that time it shows that. So, print and round all the in build functions are there. Print is not a function. But why it is happening with print? Print is a keyword. So, what print does is print is not a function. Print does not return anything. Print is a keyword, so that expression simply prints what is the expression you give print on the screen. It does not return anything, it does not do anything apart from that. Therefore, it is not going to give any output. The only output of print is what it returns, that is all, is sorry, is what it puts on screen, I am blabbering. The only output of print is what it prints on screen, so there is no out that is produced and do not worry about it. Basically, if you want to print something on screen, you have to say print. This 1 plus 2, if you put on a python file and run that from python, you will never see anything, because it is just an expression. It is not going to be printed to screen, only when you say print explicitly it will print. Otherwise, the interactive interpreter is simply doing it for your convenience. Next question is it is always returning minimum of the small alphabets, though there are capital alphabets present. So, that is an implementation detail that you have to deal with. So, if you really want to do a comparison better, you will have to do something, you will have to do it in a more intelligent way. Min is going to do something that it thinks is right. It is not going to do the right thing always. So, if you have for example, if you are transliterating Hindi and you want to find the min, does min make sense at all for a string string? It does not. Are you ever going to ask me the minimum of the string? No. If you are going to ask me to sort a set of strings, it makes sense. So, do not worry about min and max for in the context. I have personally never used min and max for a string and I have written a lot of python code. So, please trust me that in this case it does not quite make much sense to do minimum maximum of a string. So, do not get hung up on some silly detail like minimum or maximum of a string. Any more questions? Please ask them now, because after this we will be building on what we have learnt so far. I agree we have only done very basic material right now. We will be building on this and we will be looking at more details of a lot of these things. We will look at strings in detail. In between we will throw in some interesting problems that we need to solve. Then we will look at conditionals, loops, lists, input, output. So, we will be building a lot on top of this. So, any questions at this point? Okay. Question is can we reverse the sequence? If yes, how? The answer is yes, you can reverse the sequence. We will look at it in detail later. When we are doing lists, we will show you how to do it. There are ways to do it. There are many ways to do it. There is something called reversed which is a built in. There is also you can do it with slicing also. We will do it later. So, do not worry about it right now. So, there is reverse, there is sorted, you can sort. There are bunch of things you can do. So, let us not get into those details right now. Any other questions on material presented so far? Any doubts? Please ask them now, because it is important you understand whatever you have understood properly to respond. Is bounds checking performed? Well, why do not you try for yourself? So, the question is, is bounds checking performed? So, for those of you who do not understand what that means, supposing I have noom list, what if I say noom list of 100 or noom list of even 9, what will happen? So, try it. Try it and see for yourself. So, someone is asking, can you explain stride over a sequence? Okay. So, when you stride, so let us take the example. So, can you see the terminal? If I want to say, I want a sublist, I want noom list, I will take the simple example that we already discussed 1 colon 5. The result is 2345. Is that clear? So, it gives me index value number 1, which is 2, 3, 4 and 5. The index for this is 0, 1, 2, 3, 4, 5. So, the 5th index value is 6, which is not included in this. So, 1 colon 5 suggests 1 is starting value, 5 is last value plus 1. So, 1 is 2, 2 is 3, 3 is 4, 4 is 5, 5 is not included. Okay. Now, if you look at 1 colon 5 colon 2, what this will do is, in this case, I got the indices of 1, 2, 3, 4. So, I was stepping by 1 plus 1 plus 1 plus 1. Instead of that, I will now do 1 plus 2, which is 3 plus 2, which is 5. So, I will give you the first index k value, step by 2, give you 4th index value and then step by 2, I go to 6, which is not any more relevant. So, I will get simply 2 comma 4. Is this clear? Does it make sense? So, what this second colon, the index you specify after this second thing is simply saying step by 2. So, give me first index at 1, go all the way till 4, step by 2. So, it will be 1, 3, 5, 7, 9, but all those 5, 7, 9 are irrelevant because I am stopping at 4. That is what is dividing. So, if I did 1, 5, 3, it will give me 1, 4. Sorry, what I mean? So, it will give me 1, 4. 4th element is 5. So, does list inside a list represent a matrix? The answer is, well, yes and no. You can represent a matrix as a list of lists, but remember that a list is a heterogeneous. So, I need not have, the first element need not be another list. So, if every element is consistently a list and of the same size, yes, it could represent a matrix, but that is something you will have to implement. There are other ways to create matrices, which we will look at later in advanced Python. Anything else? Please feel free to ask me questions. I am not making fun of anybody, I am just saying it is an irrelevant, it does not make sense for me to answer that question and I have already said so twice. How can you access the list inside list? Okay, good question. So, I will create a simple list inside list L of 1, 2, 3, 4, close bracket. Notice here, I forgot to close a bracket, very common thing, no problem. I just came to the next line and closed it. So, L is that, so if I say print L. So, to access the first element, what do you think I will do? It will give me 1, 2. So, the first element is 1, 2. So, if I want now inside, so this is a list. So, if I want to get the next element inside the list, what will I do? So, if I want the second element, I will say this. That is 2. So, basically it is just another list. So, when I do L of 0, I get a list. That is also a list. So, I will access that element as a list. That is it. So, let us take a