how's it going everyone in today's video we're going to be learning about self in Python what it does and how we can use it in classes so first of all let's get started by creating a class called car and this class is going to take an initializer which automatically inserts self if you have a code editor it's probably going to do this automatically and we're also going to provide a brand of type string and a fuel type of type string and that's going to return none then inside here we're going to type in self. brand is going to equal the brand and self. fuel type is going to equal the fuel type but why do we do all of this well to explain that I'm going to create a car or an instance of a car so this instance will be called Volvo which will be of type car and that's going to equal a car with the following arguments the first one being the brand which of course is Volvo in this case and the fuel type is is going to be set to diesel so here we're passing in the arguments that it requires and those get passed down the line to these two lines but what you're going to notice is that we never had to pass in self into our Constructor there's no place here to actually pass in self because self is automatically filled by the instance which is this right here once you instantiate this class it becomes self so from now on self is going to refer to the Volvo so when we create this Volvo what we're really doing is creating Volvo dobr and Volvo do fuel type so this data is now going to belong to the Volvo as soon as we create it and if we were to create another car called let's say BMW that will hold BMW with the fuel type set to Electric once we create this instance self is going to refer to the BMW so that's the data that's going to be attached to BMW and that's really all self does it refers to the instance directly so that we can use the dat that's connected to the Volvo or to the BMW without self this would not be possible we want each instance to be unique and self guarantees that for the data that we use self on one thing I want to mention though is that you do not need to call this self we only name this self by convention but it can literally be anything you want you can also call it this and it will function exactly the same way your code editor is probably going to complain that usually the first parameter of a method is called self but you're not required to do that it can literally be any name this just refers to the instance you can even call this instance if you want you can say inst and change the other two and that will work exactly the same way but let's change that back to self and what I'm going to do next is create a method in this class So Def drive and as you'll notice it's going to take self once again because we want to use the D data that's connected to the current instance but we're also going to provide an additional parameter called distance of type float and that's going to return none because we are only executing code here but then we can print that we are driving self.
brand for distance and that should be in curly brackets kilomet and then in square brackets we're going to add the fuel type or self. fuel type and as you can see this will use the current instance once again while the argument without self does not rely on the instance it's going to take the data on the spot so now what we can do is print Volvo do brand Volvo do fuel type and we can even drive this Volvo for let's say 10 km and now when we actually try to run this you'll notice that it's going to refer to the instance data which means Volvo dobr will contain Volvo Volvo fuel type will contain Diesel and Volvo do Drve is going to drive our Volvo for 10 km on diesel It's using the instance Volvo as self so once again this is going to look like this vol.