 Hello, welcome to this video session. Our primary outcome for this video will be to make sure that at the end of this video, students will be able to debug Python code in PyCharm IDE. When we are in layman's word, debugging is nothing but it's a process in which a developer tries to remove bugs in our code. So during this process, there are a lot of functionalities which are performed by a developer. To have this demo, what I'm going to do is I'm going to have a live hands-on session wherein I'll be showing you how PyCharm's debugging features can be realized. Let us move to our PyCharm IDE and before we move, let us also see what all are the prerequisites before we move to the hands-on. I expect our audience to be well versed with the fundamentals of Python language and also to have a stable PyCharm IDE, preferably community editions running on their machines. If you are following the video along with me to practice the hands-on. So let us do the hands-on. So I'm going to switch to PyCharm IDE. So let me switch to PyCharm IDE. So now I am on a PyCharm IDE. What I have here, I already have a project. So I have created a project with name factorial where I'm supposed to write a code to calculate the factorial of a number. So we'll consider one fixed number and we'll try to write a factorial code so that we end up calculating factorial of that number. And we'll also debug the same program through a PyCharm code. So let us write our small Python code snippet which would calculate the factorial of a number. So what we will do is let us define a small method which will calculate a factorial. So to this we'll provide a variable number whose factorial my function gonna return. So let us write a code to calculate the factorial of a number here. So what one here and is equal to tempfair into i because our i values are iterating from number to zero. And once we are done with this we can return the value temp. So this I think we don't need a semicolons and even putting semicolons wouldn't make any difference here. So that's our method there. Now we can directly take number from a user. Let us do one thing. We'll take a number from a user. We'll say num is equal to input. We'll put a small dialog here. So then we'll take it and what we will do is we'll print and we'll directly call the method factorial here. Factorial of number. So if this is a program now what we will do is we'll not run the program. Even if this program has some internal bugs within that we'll try to figure out what exactly are bugs in this program if it has. If not we'll be at least able to go through the chain of execution where we will be able to explore variables in life. So without executing that we'll debug that and we all know that whenever we want to debug especially all IDAs or any debuggers or for any languages they come with a concept called as breakpoint. So breakpoint is nothing but a point at which your flow of execution stops for you to review and upon you step from that breakpoint you will be executing the instruction at that breakpoint location. So what we'll do is we'll just put a breakpoint where we want our execution to stop so that we can check the value here. So I want to check the value here before I return the variable so I'll just so I'm placing my cursor here and I'll click on that. The appearance of red circle indicates that there is a breakpoint over there. And this statement would always execute after loop and but at the same time I also want to see what are the variables when my loop executes. So I'll put two breakpoints here and what else I'll do is okay I think that's fine. So we'll keep two breakpoints here and here we are just printing the numbers here. So let us execute. So now before we execute let us save these contents of the script factorial dot pi and now instead of clicking on run factorial what I'll be doing is I'll click on debug factorial or either you can click debug and select a proper script which you want to execute. So I'll click on debug factorial. Now you can see that the moment I have clicked the number here it is asking me to enter number because this is the first line to start. So I'll enter a number let's say I'll enter phi and we all know that the phi factorial is 125 and after entering phi you can see that my console now directly went into debugging mode. So here I had entered input here in the console but did it print the value of a factorial? No, yet. Why? Because my program paused at this point. So when I pause my program at this point what I have are the following variables. So let me remove this. This is a redundant watch variable which I had from the earlier session. So these are the variables during the debug sessions. Now you can see that the value of i is phi because the num phi was entered here and the range starts from phi and if I execute this loop if my this expression is right you should see the value of i dropping from phi to 1. Zero is always exclusive. So this minus indicates stepping and at the same time I want them to have the value of multiplication of variables. So let me execute one by one. So now I am at this breakpoint. So now what I am supposed to do is I want to move ahead from here. So this process is called stepping. So we basically have multiple step processes. One is called a stepover which lets me directly move to the next breakpoint and we have other stepping functionalities which we call them as step into and step out. Step into is used for a breakpoint where we have a function called. And suppose I want to debug the function call and the code within that function I would always click on step into and whenever you are debugging the functions and for a moment if you find you would no longer want to debug the method but you want to come out of that method and execute the usual function call as it is you would click on step out. So step into and step out are used to enter into a method and from where you want to further debug deep down into method call chain. Right now I do not want to do that I just want to step step over from breakpoint to breakpoint a easy shortcut is F8. So now what I am doing is I am actually pressing F8 to move to the next breakpoint. So here I am going to press F8 yes I have pressed an F8 you can see that the temp has executed this line has executed the breakpoint was here it got executed since I clicked on step over the breakpoint executed it went the further subsequent instruction it is supposed to execute which is the loop iteration. Now you can see that once again it is stuck at that you can see that I values 5 and if I execute once again you can see that I values is just dropping and you can see that if I further execute this you should find the temporary variables properly incrementing. So now it is 20 yes so my assumption is right here temp into temp into I where I values gradually dropping from 5 to 1. So I am just clicking F8 and I will see if I will be ever coming out of this loop. Okay 120 yes I am 1 I am back I am at the written statement because now I have exceeded the for loop iterations and now when I click on F8 I will be coming out of this function and probably you should see the print of the factorial. So before I click on F8 let me check what output I have I do not have any output on console. So one now I am back to my debugging console and I am going to hit F8 for last time okay I am at this point. So now when I click further yes I have completed my debug execution and when you switch to console you should see the factorial is 120. So this is how we generally debug a python script what is more important here is to make sure you the choice of breakpoint should be very meticulously done. So properly placed breakpoints will let you debug the code script more effectively than improperly placed breakpoints. Show you a small concept called as watch and evaluate expressions. So this was our earlier code let me do one thing let me debug the code once again. So I will enter a number this time I will enter let's say I will enter 3. So after entering that I am on a debug console now you can click F8 to move so on to move. But remember sometimes I have this variables and sometimes I want to specifically choose a variable and make sure I specifically watch that variable. So that functionality is given to me with the help of a window called as watch variable. So here so I want to watch temp where so even this you can do that so it keeps on showing you the value of this. But generally what I prefer is we can also evaluate expression in a head. So if you see here right now the temp where is 1 I can dynamically even modify the temporary variable with the help of what evaluate expression. So if I say temp where is equal to temp where plus 10 and if I hit enter it automatically evaluate that expression and you can see that the value of temp where is set to 21 because I have evaluated a evaluate expression. So what evaluate if evaluate expressions give you they let you dynamically modify the value of a variable. So sometimes you can even modify the value of a variable with the help of watch variable as well. For example I is equal to 3 I want to set I equal to let's say I want to set I equal to 5 so I can even do this. If I set I equal to 5 you can also say that when I am able to enter the watch variable window through watch variables I was able to set here. But basically what I am doing is I am doing some kind of evaluate expression kind of stuff here. So this watch and evaluate these are two functionalities which let you deeply observe the value of variable at the same time also observe some of the changes that variable could result into some other variable with the help of evaluation of expressions as well. So now if I continue further you will randomly find some different result because I dynamically set a different variable. So let me process this you can see that now it is not calculating factorial because I dynamically changed all the variables. So though we have entered 3 I am getting this because I had modified the values of I and temp in dynamic. So this was watch and evaluate. So what do you think as a quick reflection in this video what do you think? Does watch window let you change the value of a variable? You can pause and you can revisit the video and you can answer but the answer for this question is yes it lets you change the value of a variable dynamically during execution. So this is the bibliography and that's it for this video thank you.