 So, what we have looked at so far is, we looked at strings, how to create strings, how to access their elements, how to do some basic arithmetic kind of operations in strings, access the elements, we notice that strings are immutable, we solved a little problem by looking at slicing in great detail, striding, then we looked at string methods, keeping in mind the fact that strings are immutable, solved the problem, looked at join and I also demonstrated for you split. Let us look at conditionals next, so what I will do is, we will finish conditionals and loops before we get to lists, lists we will do in the afternoon, so let us look at conditionals. Now, python is a fairly simple language in terms of conditionals, there are not too many conditionals, typically you will use the if, if else, if else blocks which we look at now. So, consider the code here, this is python code where I am saying first a is 5, so what have I done, I have created a variable called a to which is assigned an integer 5. One thing you have to remember is, unlike in statically typed languages, a can now be a string, later it can be an integer, all of that can happen, it is up to you, you determine what a is, it is not fixed in time, so you can change it, a can be an integer now, little while later it can be a string, it is up to you, so you as a programmer have to be careful about how you write it and how you make sure that you do not confuse yourself and other people who read your code. But getting back to this if code, so a is equal to 5, simply a variable declaration to an integer, if a percentage 2 double equal to 0, so this is how you express a logical condition, equal to is an assignment, double equal to is conditional, you check, so if a percentage 2 is equal to 0 means what, is it divisible by 2 essentially, if it is divisible by 2 it is even and now notice that anything inside this if is indented one level to the right, now indentation in python is very very important, all of scope is determined purely by indentation, many of you will be saying, why do not you have brackets to indicate in scope, it turns out that if you put brackets everybody has a different bracketing style and some people have no style at all, which makes code very difficult to read, but python therefore enforces that you must have indentation to determine the scope, so in this case everything that is indented one level to the right is inside this if condition, if you did not back to the level of the if, then you are outside that if condition, now one note in indentation, I would suggest that you do not use the tab key and instead use spaces when you do your indentation, reason is you cannot mix tabs and spaces when you are doing your indentation, in one python file avoid mixing tabs and spaces, so as a rule if you have an editor, many editors have this configurable, in them for example it is called expand tabs, similarly in emacs there is something like that, even in g edit and all of these other editors, if you look at the program or if you look at the properties or the features, there will be one thing which will say use spaces as tabs, so every time you type tab it will convert it to some equivalent number of spaces, I would suggest you use spaces in your code uniformly, do not use tabs and I would additionally suggest that you use four spaces as a tab, do not use eight because eight becomes too much space, so use four that is a recommendation that I am making, it is not compulsory but I recommend that you use four and I will use four in the subsequent set of slides, all the slides that I demonstrated, so if A percentage two zero it executes this block, else it executes this block very straight forward, so let us try this out, A is five and I would suggest you also try it out on your local sessions, A percentage two equals zero and even also this, I am just modifying it so that you can see that, now if I have to go to the else, I cannot type else here, I have to go back, now I type, now notice that it is not giving me back the impromptu, so you enter this twice, now since A was odd, it said odd, it is, so remember indentation is important and more importantly by the way is many people will forget to put this colon, so if you say for example, if you forget this it will be syntactically incorrect, so every block is indented and before that block you have a colon, semicolon not semicolon, colon is the character you have to use, now if you do not have an if, if you do not have an else that is fine, so I can say if A percentage two that is also fine, you do not, else is not compulsory, but often you will say if else if right, so instead of else if there is a condition, there is a thing called L if, it is kind of like bash, so you say if A greater than 0 positive, L if A less than 0, negative else and only one of the blocks gets executed, very straight forward, again remember indentation, semicolon, everything indented one to the right is in that scope, for example, let me make a few mistakes, if A is greater than 0, gone, I cannot put an L if, if I put a new line after this, I cannot say L if after that, so if you are using an editor and you are typing this, make sure that the L if and else blocks are together, so this is very straight forward, the other thing is else is optional, so if user is admin do something blah, blah, blah, notice that there is no else block here, that is perfectly legal, now very often you want to do an assignment very conveniently, but without having to write a 3 line if or a 4 line if condition, so for example, let us look at this simple example, there is a variable called score underscore str, that is either a string of a a indicating absent for a student or a string of the numbers in the range 0 to 100, some mark, it is the score of that student in that paper, we wish to convert the string to a number using integer, so this is one thing that I have not shown you yet, supposing I have let me make him pass, so let us 50, if I want to convert this to an integer, I can do int of, this will convert it to a integer, I have not shown you this explicitly before, so int of a string with a valid representation, so for example, if you say int of that is invalid, which is value error invalid literal for int with base 10 score, it does not know how to convert score, so what I want to be able to do is I want to say essentially I want to do this, if score str not equals a a, score equals int of score, else score equals 0, now you will find this is a very common requirement, you have to, in this case it worked but sometimes score could be a a, score str was a a, how do I now make this simple, so it turns out there is a ternary operator which can do this in one line, so I can say score is equal to int of score str, if score str not equals a a, unfortunately my font is too big, so it does not fit in one line but you can look at the code, so let us just switch to, so now what to say, let us just switch to the presentation, all I have done here is I have made this line shorter by storing this in another variable called ss, ss is score str, score is int ss if ss is not a a l0, so in one line I have done what four lines do here, it is a very convenient thing you will use it repeatedly and the format is score is what you want under the condition that this is true, otherwise so what it does is it will first evaluate this condition, if it is true it will evaluate it to this, if false it will do, so it is very easy to read, score is int ss if ss not a a l0, it is called the ternary operator and it is very useful. The last piece when you are doing functions, when you are writing conditionals and generally when you are doing anything with this indentation, supposing I want to say the following, let us switch to the terminal, if a percentage 2 equals 0 print even but I want to do nothing when it is odd but I do not, I want to have that else case and do nothing, I want to write it so that the code looks clean, so I can say if it is even do something, if odd do nothing, in this case you can use what is called pass, pass is what is called a syntactic filler because if I put else colon, the colon will indicate that the next section should be indented, when you say pass it will basically say there is nothing to do, this is also useful when you are doing functions and when you are writing your own code, so you are writing functions and you are trying to get an idea of I want to write this function which does something, that function which does something, you are not interested in the details of the function, but you want to just say that function should be there, it should take these arguments, you define a function and you say pass which means you will come back to looking at the code later on but you want to just create a dummy function, then you say create that function and say pass inside it will basically, it will compile as legal python code but you will do the implementation later on, so pass is something you will see very often when you look at code and when you write your own code, so it is just a note that you should keep in mind, so that is it, so there is only an if conditional in python which makes the language rather easy to read, there is no switch case, then none of that is there, it is just if and only ifs, if, l if, else that is all you need to know, so loops get a little bit more involved, so let us look at loops, so we look at the while loop, so I will show you the simplest while loop that is possible, let us print the squares of all odd numbers less than 10 using while, so to do that first set the some variable to i to 1, while i is less than 10 and i star i, i plus equals 2, so you will also make mistakes when you type, unfortunately the version of ipython I am running does not seem to have multi line editing, first mistake you can make is you forgot to increment the counter, now it is going to go into an infinite loop, so how do you stop, let us control c, it will get out of that, so now let us go back i plus equals 2, so now it is printing the squares of all odd numbers less than 10 using while, so the basic syntax let us switch to the slides is while condition, this has to be a Boolean condition typically, any semi colon very important, anything inside this indented block is going to be run as long as this while loop condition is true, so if it is always true, so for example if I want an infinite loop I can say while true pass, now control c will get out of it, notice that I could also do it like this, this is also legal, basically pass will block will basically assume that there is no further block, so this is very simple, so there is nothing more to while, you need to establish a condition everything inside this condition is executed as long as this condition is true, there is no do while in python, the other thing is for the next looping construct is for, what I will do is I will finish for and someone has asked a question I will answer, may be before I get to for I will answer the question, can you give more examples on join and split, I do not know, so I can give plenty of examples on join, I think I already gave you fairly many examples, so join jbc that is join and if I actually give a lot of examples, I do not know if I can give more, there is nothing more to it than I covered even all the optional arguments, I covered the separator, so I can now say separate on, if I do not give any options for the split, it means it will separate on any white space and remember I showed you an example where I gave multi line input, where I had new lines that is new line is also considered as white space and that is also handled, whereas if I say split say on the letter s or let us split on is, then it will be th space space a string, let us split on s, you will get something, so basically you can give it a separator argument and you can say I want only the first split, it is a max up, if you do not specify a max up, it will split all of it, join is very straight forward, just give it a string, it will join on that, so if I take notice that it does a, so essentially you can think of it as instead of these commas here, it is replacing it with this string, it can be any string you will supply, that is pretty much all there is to it, perhaps interesting things you can do like this, notice that the join argument is a sequence, let us see if this works, that does not work because it expects strings, each element of that sequence should be a string, but this works because hello is a string and each element of that string is a string, so h and e and l and o, let us try one more thing, this will give me back hello, what if I give the empty character as split, what do you think they should do, it will tell me error, I do not know how to split it on empty character, it knows how to deal with this, as does it know how to split, notice that it is when I did h e l l o dot split l, it says h e empty string o, because it is saying between these two l's there is nothing and it is giving you that, I think I have given enough and more examples of split and join, so much so that people may complain that I am doing too much on split and join, let us move on, you have about 5 minutes, I will wind up with for looked at container ship, for n in some sequence print n, for example, this example is, so let us try this out for n in 1, 2, 3, semicolon indented block print and now it prints 1, 2 and 3, so essentially at every iteration level n is initially n becomes 1, then n is 2, then n is 3, so n is a variable that is first 1, then it is 2, then it is 3, for example, I could do this, so it will be 2, 3, 4, very simple very straight forward, so essentially you can think of it as 4 iterates over every element of a sequence and now this does not have to be 1, 2, 3, it could be, because it is a sequence, it can also be a string and since n is a variable, you can have any name, so let us slide to something little more complicated for c in, so for c in s, if c is, I am combining both things that we learned and make it a little better to print, notice that it is basically when I, instead of saying print c, if I do print c, it will only print a space instead of a new line every time, so all I am doing is, if it is a, b or c, I am not doing anything, if it is anything else it prints, some silly code, very stupid code, I just combined your conditional along with looping, so the general structure is for variable name in some sequence, do whatever code inside this block, that can be anything, for iterates over each element of a sequence, now one common thing that you will often need is, you will typically you would say for y, you typically in c you will say i is equal to 0, i less than 10 plus plus things like that, so there is a built in called range, what range does this, it returns a list of integers typically and the syntax is kind of like our slicing syntax, start, stop and step and this stop is not included, so if I say for, I say range of say 5 by default, start is 0, I have only specified the stop element, 5, 5 becomes a stop and step is 1, instead I can say 0, 5, 2 that will be 0, 2, 4, so I can say for x in range 5 print x comma, so for loops are extremely convenient because it allows you to iterate through any iterable, any sequence, you learn later on there is something called an iterable, so anything that is iterable you can iterate over elements of that, sequences are iterables and range can be used to generate a list of elements quickly in a convenient fashion, so if you want iterate over some set of elements you can do that, so what we have looked at now is loops which are while and for, so it is very simple, there is nothing more to it than that, there are additional details to how to use for, for it can be a little more, there are more details that you will learn later, while loops are simple but these are the only two looping constructs in python, there is no do while, there are few more constructs you can use inside your loops, one is break which is very similar to what you have in C or other languages, what it does is it breaks out of the innermost loop and please remember it only breaks out of the innermost loop not the entire loop, so we have two nested loops one for inside another for, the innermost break will only break out of the innermost loop, so for example this code here produces the squares of odd numbers below 10 using while and break, so it says initializes the counter to 1 while true, please note while true is ordinarily an infinite loop, so what it does is print i star i, i plus equals 2 that is the same as what we had before but in addition it says if i is greater than 10 so let us just try this, the other construct that is often used is continue, so what it does is if you hit a continue, so let us look at this code for n in range 1, 10, 2, so what will this, if I just print without this it will print the values of n would be 1, 2, 3, sorry 1, 3, 5, 7 and 9 correct, why because range of 1, 10, 2 will be 1, 3, 5, 7, 9, so n percentage 3 is 0 continue, it means it will not execute anything below this and jump back to the start of the loop, so let us try this, so for n in what it printed was 1, so it is divisible by 3, it did not print, however if I put the print n star n on top, the answer would be different because if you continue at the end of the block it does not mean it make any sense, it will still execute that print state, so you have to be careful about where you put your continues, how you do the continue, so there is a question between of what is the difference between pass and continue, the big difference between pass and continue, so my suggestion to you is you please try it yourself, you put pass here and you put continue here and you tell me what the difference is, what do you expect, question is what is the difference between pass and continue, what will happen if I put pass here, why will it be stop, whoever said that, while true is an infinite loop, while true pass is an infinite loop, pass is nothing, it is just syntactic block indication that is all, what will happen, so I want you all to try this and before you try it, think about what is happening, what is pass, this answer is clear, what happens if I did this, this will be an infinite loop, so if I did pass here what happens, it will do nothing, it is like a no op, nothing, do nothing, so it will print everything, it will not do what you expect, so pass and continue are entirely different, we have finished with looping constructs and the next concept is list which we will consider post lunch.