Okay, so now that we've gotten through the definitions, let's work into some sample code. But hey, look at this, we've got ourselves a cookie cutter and some cookies. So remember that a class is a template, it's not the actual thing. An object is an instance of a class. So you have to take the class and do something to make the object. And actually you can see here's some other classes. There's clearly a sort of a snowflake class and a gingerbread man class, that's an object, object, object. Somewhere out here there is a snowflake class and a gingerbread class, but we got a snowman object and a snowman object in a snowman class. So class is the template, object is the instance. So here's a bit of Python code. So let's take a look at what we've got here. Class is a new reserved word, kind of like def. We have the name of the class, that is a name that we choose, that's the name by which we'll refer to this class for the rest of this program. And it has a colon at the end of it, which means it starts an indented block which ends when we deindent. Inside the class there are generally two things. There is some data, and this just looks like an assignment statement in the class, x equals zero, and then there is a def. This looks just like a function in that it starts with a def, has a colon, indents, so that function finishes right there. The difference is this is a method because it lives inside of a class. And so there is no function called party, there's a function called party within the PartyAnimal class. And we'll talk in a second about this self thing, it is the way that inside this code we refer back to that variable. So this is not actually executing any code, it's sort of remembering the template, defining the class PartyAnimal. This is what we call constructing, we're constructing. Using the PartAnimal template or class, we are making a party animal. And then once we make that, we stick it in the variable a n, and then we're going to call this party method three times, one, two, three. Now this self thing, and we'll take a look at the self, the self ends up being an alias of a n, and so you can look at this syntax as just kind of an equivalent of this syntax. It's calling the party method within the PartyAnimal class, and passing the instance in as the first parameter. And so self ends up being an alias of a n each time these are called. Now if we make a different variable and a second object, which we will eventually, you will see that that works a little bit differently. And so this syntax is a short version of that syntax. So if we watch how this executes, whoops, it starts up here, it just defines it, and then we construct it. And that's what basically constructing it, we know how to construct it because we look at the class and we make a variable x, we make some code party, and then we construct that, that's what the PartyAanimal does. And then we assign that into a n, and so a n is now pointing at that. Then when we call the party method, that basically takes this a n and passes it in as the first parameter which is used as self. And so self.x, which is what we're doing in this line right here, self.x is a variable. x starts out as zero, x starts out as zero because when it was constructed it was set to zero. So we're in here, a n is an alias of self, and now it looks up self.x, which is zero, adds one to it, and so this becomes 1. And then we print so far, So far 1. And then the code returns and it goes down and does it again, and x becomes 2, prints out So far 2, comes back down and does the last time, calls it again, self.x is 2, add one to it and stick it back in. So this becomes 3 and we print out 3, and then the program finishes. And so you can think of this as constructing the object and then associating it with this a n variable. Now that we've created this object, we can play around with things we've played around before with dir and type. We use dir and type to kind of inspect variables and types and objects. So we've been using objects all along. This code here says, hey, make me an empty list. Well, it turns out that what we're saying is there is already a list class inside of Python, and we're constructing an empty list. And when we get back this empty list, we're assigning that into x. So x in a sense contains or points to an empty list. So then we say, hey, what is in x? What kind of thing is x? Well it's a list, this is a thing, it's a list type. And lists have lists of things in them. And use append and all the things we've been doing before, they are just objects. And then the dir, if you remember the dir, the dir is the capabilities. And there's all these internal capabilities that do things like implement the bracket operator, etc. The double underscore ones, we can ignore them. Although you can even look them up and figure out what they mean if you feel like it, but the methods that we tend to call are in this class. And so things like x.sort, I've always told you that is the sort method within the x thing, and the dot operator is the operator that we use to look something up within an object. And so you've been using this syntax all along, x.sort, dictionary.items, all of those are methods within the corresponding class. If we take a look at this line of code that we've been doing for a very long time, which says, oh, stick 'Hello there' into y, if I reword that as more OO or object oriented, what this single quote does is says make me a string object and put some text in it. And then when that is done being constructed, stick that into y, right? And so y now points to a string object that's been pre-initialized to the string Hello there. Now, that's a long way of saying Hello there ends up in y, but in OO terms we can talk about that. If we do a dir of that, we see a whole bunch of internal methods which have double underscores, and then we see all kinds of methods that we've been using. We've been using methods like upper, we've been using methods like find, we've been using methods like rstrip, right? We've been using these methods, so we go into like y.rstrip, parentheses. Again, that's a method, that's an object, not a class, it's an object, and that is the object lookup operator. Now if we do the same thing to code that we've built, or a class that we've built, so now we have a PartyAnimal class. Remember this up to here is just definition. Now we construct it and we store it in a n, so a n is a variable that contains an object of type PartyAnimal. We asked it what type it is, and prints out here. It says this is a class and it's main underscore PartyAnimal, and this whole thing here is underscore main, it's scoped to underscore main. But you can see that you have made a new type, you built a type by using this class keyword. And then we use the dir, remember dir looks for capabilities. And again, you will see a whole bunch of underscore things, they have meaning, you can look them up. But eventually you'll see the two things that you've put in it, one is the method party and the other is the attribute or field x. And again, these are the things that you can say an.x or an.party, because this dot is the object operator, the object lookup operator, that says look up in the object a n the thing x, or look up the object a n the thing party, okay? So up next we'll talk a little bit about how objects are created and destroyed. We also call that object lifecycle. [MUSIC]