 What's going on guys? Root from NullShell.com here today and we are looking at some more Python code. Now, lately we've been taking a look at object-oriented programming and if you guys need to refresh your object-oriented programming or OOP is the sort of like idea or the mindset that we can use objects or instances in our code. And now these objects and instances and code can be, I'm sorry, the objects and instances inside of our code can be thought of as sort of like machines. They have sort of properties, they have attributes and like qualities to themselves and characteristics and traits that we can think of as the variables. And now we have these actions and these processes and these things that they can do that we consider to be the methods or the functions. So let's give it a go. Let's open up idle and I'll show you what we're going to get at today. I am going to be creating a new script, but we're going to be working with it inside the interactive shell after we've got everything typed out. So first of all, I'm going to save this as file.python, get my shebang line going on, environment Python and we can begin. Now, when you have an object inside object-oriented programming, you have what we call a class. And this is the terminology that I want you guys to know for today, classes. Classes are what a programmer uses to define the blueprint or the framework or the sort of structure that an object goes into. It becomes sort of like an incarnate of that class. It becomes an entity with all those qualities, with all those functions and that sort of thing. So let's give it a go. Let's try it out here. What you have for a syntax, first of all, is you have the keyword class and then you have the class name. So this is where it would go. In my case, I'm going to call it a person. And now you just start a colon here and get a code block going. I'm going to use my comments because that's just sort of my style and we'll give it a go. So first off, I'm going to create a function. I'm going to call it a set name and say self. And self is the new keyword that I want you guys to be looking at because self shows the class that anything is going to follow this is specific to this current object that we're looking at. So for functions, it always has to be the first parameter and you don't have to pass that in, but you have to have that set up when you're defining functions inside of a class. So if we have self and then we can say name to be set as, we can start a new code block here. And now we're going to use that self keyword again because we're going to apply some qualities or some characteristics to this specific object. So if we do self.name, so this current object, this object, its name is going to be equal to whatever we set it as. Name to be set as or that string that we pass in for the function. So now we can define another function. Let's say hello and get everything set up here. And we have to include this self keyword. Remember that because we're defining a function inside of that class. We aren't going to bring in any other parameters, only this one, because there's just no need to. It's just going to say hello by using the self name variable that we've already set. So we can just do print to display some standard output and we'll do self.name plus equals says hello. We've got that all set and now we kind of have our little class. We have everything that we need. But remember we are using these keywords class and we're using the keyword self. So now it's time to create an object and now the object is what's going to become the sort of manipulatable thing or that structure or that data that you can work with. So let's just have a variable like Andrew and Andrew is going to be the object. So now the way you set this up is you can have an equals and then you're assigning it and then you're going to want the name of the class and then you're going to have those two parentheses afterwards. So if we run this with F5, nothing happens because we haven't done anything but the object has been initialized. If we try it here, we type in Andrew, inside the interactive shell we can see that inside our current scope, the main scope we have an instance of person which is our class here and this is the memory address of where it's at. So Andrew is our person and now we can do things with him. We can run Andrew set name and now if we actually use the call tip we can use control backslash here and we can see the string or the variables that we need to pass in. So name to be set as, we will set him, I hit the enter key there, sorry about that, we can name him Andrew Richardson. Now Andrew's name is Andrew Richardson. So if we do Andrew and then dot, we can see the core variable here, we can see name Andrew dot name if I actually remember to do this. Andrew Richardson is stored in that variable. So if we set up Andrew dot say hello and we run this function, Andrew Richardson says hello. Now we can do this inside the script obviously, we can set up Andrew equals actually Andrew dot set name. I just cannot type today. We can set his name to be Andrew White or something else. And now we can run this. Nothing is going to happen because we haven't displayed any standard output. We can use Andrew equals actually Andrew dot say hello. No parameters because we don't need anything, self gets filled in automatically for us. We run this, Andrew White says hello. So here we have a new thing. We have all these but let's see if we try to run say hello before we set the name. If you guys that are understanding this, the procedural end of this, this is going to throw an error because name has not been set yet. Person has no, the person instance or Andrew in our case has no attribute name. The variable has not been set but because we've set it here, we don't have to worry about that. We could fix this. We could set an optional parameter here right up here. The name to be set as can be equal to nothing first of all. But that still doesn't solve the problem because it's not being initialized automatically. We have to run this function for the name to be set. So we can tackle this in the next tutorial. That's a whole other thing. And that's a whole other topic but there is a workaround for that. But now we have our object Andrew. What if we created a new one? What if we created a new person? We can call this Kyle. Let me get my workspace back. And Kyle can be Kyle Roberts. So now that we've set these names, Kyle is a new instance that it has the name Kyle Roberts. And Andrew is another instance that has the name Andrew White. So first off we're going to see Andrew say hello. He's going to say Andrew White says hello and then we have Kyle Roberts who is going to say hello. So if we run this, Andrew White says hello, Kyle Roberts says hello. And we can do this as many times as we want. We could have like Billy, we could have Doug, we could have Tony, we could have Kevin. It doesn't matter because we can create so much of this same structure, this same setup. This person instance has all these functions that we declare. They have all these properties that we declare and that sort of thing. So yeah, that's all I wanted to show you guys in this tutorial. Classes and self are the keywords that you should understand and be able to know. And classes are the core of object-oriented programming. This is what you need to be able to create an instance, obviously. So yeah, thank you guys for watching. I hope you enjoyed this. I hope it's helping you out in your little Python world, your little journey to become the very best Python trainer. Not a Pokemon trainer, mind you. But thanks again, guys. It'd be awesome if you could give me a like, maybe leave a comment, tell me what you think. Maybe subscribe, I don't know. See you again in the next video.