Form. In this short segment, I will introduce you to Python programming. At this moment, it's important to know that I'm expecting at least some basic level of programming knowledge, so even if you have never worked with Python, it is expected that you've done some programming. And, no matter what other language you've used, Python is a very general-purpose programming language. It provides high-level of programming tools so that one doesn't need to know a lot of machine level or intermediate level programming And be able to express the statements in a more human readable format. Python is very simple as it's great for the beginners but it's also easily extendable using huge number of tools and tool kits that are available for Python. Since it's very powerful, it's free, it's open source, and it's one of the most popular programming languages for doing data analytics, I'm going to assume that you have access to Python somehow. But, if you don't, then I recommend first pausing here and downloading and installing Python. I'm not going to provide all the details here, because I want to keep the focus on actually learning Python. But, if you go to this website, you can find, download, and install Python. In addition, we're also going to use a platform called Anaconda, which is for doing Python development. So, you can download that from here. What Anaconda does, it actually has tools, and I'll show you in a moment like this. This is the Anaconda environment, it tells you what Python you've installed. It actually connects with it in the back end, and then it has all these front end tools. Some of them come pre-installed, others you can download through this environment and install. The thing that we're going to use Is called Spyder. All right, so again this is within the Anaconda environment. There's a tool called spyder, so we'll use that. This is what spyder looks like. This is what it looks like, so here I'll explain quickly the main components. This is the editor, this is where we'll type our program or any statement. This is a consult and you can actually run your Python code straight here and up here you will see different things depending on what you wish to do. Sometimes you see help if you need more help we'll see variables popping up here. All right, so we'll get back to that, but first let's just get started with doing some stuff with Python. So, the basic thing you can actually just type stuff here, if you want to print something You can say that here, and hit Enter. So here, print is a function or statement, and this whole statement, I'm sorry, this print is a function and this whole thing is a statement. That is about printing something on the screen, right? So, once you hit Enter after this thing, you just get this output, which is just Hello, World, but you can also do more than that. You can enter some kind of a mathematical expression like 2+2, and you get your output as you would expect. In addition, you can assign these values to variables. So, x, let's say, is a variable, you assign 2 to that and you assign 2 to y, and then you can write a little expression like z=x+y. And now, if you ask what z is, just enter z and that tells you the answer. So plus is one of the operators but of course there was minus, multiplication, division. So for instance you can say z is actually x multiplied with y, so this is the multiplication, and again, this is one of the reasons why it's called a variable. Because you can assign any value the value off that variable varies so now Z is X multiplied with Y and you have X plus Y and now if you ask what Z is Well, this wasn't a good example, because multiplication will result the same thing. So, let's change the value of Y. Now, if Z equals X plus Y, then you get five. If Z equals X, multiplied by, then D will be six. Okay, so that's just simple mathematical operators. You can also use logical operators just like you would use in any program in language. So, for instance, if I ask if two greater than three, I get false. All right, so greater than is that logical operator. I say three greater than two, then that's true, so that's an example of logical operators. And at this point, if you switch to this variable explorer, you can see that there are these variables that are recorded here with their type. If you've done any other programming language like C or Java, you know that there's integer type, which is for representing whole numbers. The good thing is in Python most times you don't have to worry about variable type. But if you are curious you can find the variable types as well as the values stored in those variables right here in the Variable explorer. Okay at this point, let's go ahead and actually type something here So let's imagine you want to find out if a given year, or some year is a leap year or not. So we assign a value to a variable called year, and then we can check for a condition. All right, so one way to kind of figure out if a year is a leap year or not, is to divide it by four, and see if the remainder is zero We can do that easily using the modulus operator, which is that percentage sign. So, you divide year by 4 and check for the remainder, and if that remainder is 0, then you would say, well, okay, it's a leap year. Otherwise, it's not a leap year. So, very simple program. Now once you type this, you'll have to save that programme before running it. Normally, Python scripts programs are saved using .py, so make sure you save this, and then I'm going to hit this Play button to run it. You can see here in the console that the granted and output is leap year, and again, you can see the variable changing here, variable explorer. So, 2020 is a leap year, but let's check for 2018, again make sure you save it, and then you run and then you see that 2018 is actually not a leap year. So that's a very simple program and you can see the things that we use here assigning values to variable, writing first this is a arithmetic expression, doing the modules operator, looking for remainder. And then this is a logical operation because we are looking for A similarity, we're just looking for a match. So == is for matching these, left and right side. And so this whole thing is a condition. And that condition is of this, and if it's not true, then execute this. So it's a simple program, but introduces you to several new concepts. Okay, let's go ahead with a different example, let's say you want to do multiplication the old fashioned way, so you have Two and you have three.That you want to multiply.So one way to do this,is to take one number and to add it to it's self.The times that the other number is. Okay so in this case add two to itself three times and so this is a repetition that we have to do and so for that we can use a y loop and we can say as long as a is less than equal b. So we want to run Something that we time. And what we're going to do is we're just going to take a Equals a+b And once you come out of the loop, Print a, save it and there we go. So let's imagine you're trying to do the multiplication the old fashioned way. And so you want to multiply, Two with three. Okay, and so the old-fashioned is you take one number and add it to itself, however many times the other number is. Okay, so we'll also need a couple of variables to keep track of things as we're doing, so we need a Counter. Again if you have done any other program language, you come across some way of running a loop using a counter okay. And then where are we going to store the answer. So let's initialize that to 0. Here we'll write a while loop that allows us to go through some process multiple times And so we're going around this wild loop. Once again, what we're trying to do is add this number to itself this many times. Okay. So this many times essentially is our counter. So we start counting from zero and go as long as we have that other number. Okay so while counter is less than b and what we do is we say answer is going to be answer plus a and counter is going to be counter plus 1. Yeah so these are wild loop and what we're doing in that, we have two statements. We start our answer to be zero and add a to it. Every time we're on this loop we are adding a, so we start with zero, add two to it then add two again, two again, and we do it this many times, and so we're keeping track of how many times we're doing this, right. So, that's where counter, it starts with 0 and every time we go through this process, we incriminate the counter. Okay, and when we're done, we want to print the answer. All right, so make sure you save this program, and once you're done, run it, they can see that your answer is six. Okay, so that's two multiplied by three, of course we can change this to something else, and see if it comes out right So here's then your answer. So this is a way to do the multiplication, but of course we are doing this to introduce this concept of loops. This is how you write loop in Python. This is while loop. Okay, and of course it's not the only loop. It's it's a a one of the most popular loops. Because it allows you to put any condition and it worked through things but there comes when you know how many times you need to go through things so you could also write a four loop. So let's just Turn this into a four loop so we can say four and in this case we know that we need to run it b number of times so we're going to say for Counter in range (1, b) and we don't need to do this statement here. So what we're doing here. We turned this into a four loop. We're saying that look out for this counter. As long as it's in this range, One to b. And so you start with one and then it goes to b, you keep doing this particular statement, okay? And so then you just kind of run this one, Turn this into a for loop. Okay? So for loop is useful when we know how many times we need to run this. Right and this case we actually know how many times specifically. So we'll modify this slightly by saying For a counter that is in the range of zero going to be. Okay so essentially what we are doing is we are taking care of this particular statement where the initialized counter is zero so we remove that and we are Putting this here right. So it starts at zero. It runs b number of times. So everytime this loop is executed it automatically predicts to the next step. So we almost don't need this statement. So you see how we got rid of two statements like this by introducing the far one. And if you run it, you get the same answer. And so it basically does the same thing except that it's now, it looks much more elegant in a way. So form up is useful when we know how many times something should be executed and while up is great because it's more general purpose and it can take care of Almost any kind of condition whether it's something where we haven't checked for some logical conditions like we did here or we know exactly how many times the loop should be executed. Okay, so these are two kinds of loops that we talked about. Okay, with that, let's look at a summary of what we did. And so we saw how to launch and use Spyder, this is what we're going to use for writing Python code. At this point again, I'm assuming that you've done some kind of programming before. If you haven't, please revisit those things. If you haven't done it for a while, then som of those concepts like variables and loops, While Python is very forgiving and it does not care for specific data types to be explicitly specified, it's good idea to have a general knowledge about those things. We saw arithmetic and logical operators. Again we didn't see all of them. But two examples hopefully will read as it's some of them. We talked about data types, again python is not very picky about it but it's good to know and we saw how to write condition using if Ls and loops using one N4. So that's our short introduction to python programming.