 In this video, we are going to look into a nice online tool called PythonTutor. It helps us draw memory diagrams in an automated way. So let's first create a new file and call it PythonTutor. And let's start with an easy example. Let's go ahead and assign to a variable A the number 42. In the same time, let's create a list, let's call it x. And let's assign to it the list object with the numbers 1, 2, and 3. So in the memory diagrams that are true in previous videos, we saw how Python translates this code into a memory diagram. So first, the first code cell is evaluated, we create an object of type integer with the number 42 in it. And then we create a name, let's call it A, and make A reference the object 42. And then similarly, Python creates a list object like this. It puts equalized slots in there. And in the previous video, I did not tell you why I threw way more slots than we had elements inside the list. And I will talk briefly about that in this video. But now, for the first element here, we are going to create an integer, the number 1. We'll make the first slot reference it, then we go ahead and we create a second integer object to number 2. And make the second slot reference that. And then let's take here the third integer object and int. And let's go ahead and make the third slot reference that. And then after the entire list object has been graded, we go to the left-hand side, we create the name x. And we make x reference the list. Okay. So let me also briefly put in the index numbers. So we start counting at 0 as we learned before. So the indices go like this. So here in this diagram, I have nine slots in total. So the total number of slots that are created when a list object is created is basically a so-called implementation detail of the Python language. However, you can be sure that there are going to be more slots than you will put elements initially inside the list. And the reason for that is simply that is an optimization. As we learned in a previous video, you are allowed to change the 0s and 1s inside a list object after you created it. Okay. That means, as we saw before, we can, for example, replace the first element in the list with a new object. And we will do so in this video as well. Also, but we will also compare that to the online tool Python Tutor that I will introduce in a bit. Okay. So because the list object is mutable, Python assumes that maybe after you created it, you may want to place further elements inside the list. And because of that, it reserves already some space in memory so that you can easily just put another reference in there. So this is an optimization, really. And let's say you add further elements one by one. And at the end, you're going to run out of space. You cannot put any more references inside the list object. Well, what's then going to happen is Python will go to a different space in a different area in memory and create a double sized list object. And we'll copy paste over all the references. And then in the new list object, you have a new empty slots then. Okay. So having a couple of redundant empty slots here is an optimization so that when we have to, when we want to put in further elements, we don't have to create new list objects and copy paste over all the references all the time. Okay. That is just the reason why lists are usually a bit bigger in memory than they are in the source code where we create that. But now let's go back to the web browser here. And now let's go to a website called PythonTutor.com. So PythonTutor.com is a tool that allows you to create memory diagrams just like the ones that I created that I draw here by hand. However, you can do that in a automated way here as well. So let's click here on start visualizing your code. And this will take us to a new site where we can enter code and we see that PythonTutor is a bit outdated in terms of which Python version is running. So the latest Python version here is 3.6. We are in this course using 3.8. That's not a big of a problem for what we use PythonTutor in this course for. So let's copy paste over the code that we have in the Jupyter Notebook. Let's say we assign to X the number 42 and let's assign it was A. And then let's assign to X the list object 1, 2 and 3. So this is the same example as we have here in the Jupyter Lab. And then we click here on visualize execution. And now what's going to happen is on the left hand side, we see the code that we just entered. And on the right hand side, we see the memory diagram. And here where it says frames. This is basically the same as here the left hand side where it says names here. And the right hand side in the PythonTutor example here, this is called objects just like it is also called objects in our diagram here. So let's continue here. So what can you do in PythonTutor? Well, if you click on next here, what's going to happen is the next line here that is shown here in red with the red arrow, this is the line that is going to be executed. So this is a nice thing about PythonTutor. It allows us to run code in a stepwise fashion. So in other words, we are basically running the code in slow motion, so to say. So let's click next ones. And this is going to create a variable called A and it's going to assign 42 to it, just like we do in our hand-tron diagram right here. However, there is a big difference and that is why I like PythonTutor, but I don't like it for beginners quite yet because PythonTutor makes some simplifications. So what we see here is on the right hand side we have an object, on the left hand side we have a name and they are connected with a reference. If we go back into PythonTutor, then what we see, PythonTutor makes the simplification of writing the 42, the number 42 on the left hand side right next to the name. So in real life, so to say, the 42 should be an object here on the right hand side, but PythonTutor being a simple web-based tool, it makes here this simplification of putting the 42 right here. However, if I execute next one more time, I create a list object and now what we see is we see that now we have x as a name on the left hand side and now we have a reference going to a list object containing the numbers 1, 2, 3. However, also regarding list objects, PythonTutor will make a simplifying assumption. So if we go in our hand drawn diagram, we see that the numbers are objects on their own. So inside the list, the only thing we store are really references going to real objects. However, in PythonTutor, the numbers are also shown right in the list. We have slot 0, slot 1, slot 2 and the numbers 1, 2, 3 are just inside the list object. So if we know that, if we always remember that this is a simplification, we can perfectly work with PythonTutor and we will do so in this course because for some diagrams that are highly interactive, it is actually a lot easier to create the diagrams with PythonTutor or some similar tool. I will not draw a manual diagram for all the videos but always keep in mind that the PythonTutor always shows you a little bit of a simplification and maybe I can give you a rule for that. The rule is whenever the object that is to be represented here, the numbers are immutable so they cannot be changed after they have been created. That is when PythonTutor just makes a simplification and puts them right where we assume they are anyways. But in reality, we know that they are really objects on their own having references to them. So that is PythonTutor and that is how we can generate Python memory diagrams on our own without having to draw all the time. See you in a future video.