Python OOP Tutorial 1: Classes and Instances
Corey Schafer
We 'll be learning how to create and use classes within python and how object-oriented
concepts are applied within the language now There 's a lot to cover when working with classes
so I 'm going to break these up into several different videos. We'll learn about inheritance class
and instance variables static methods and class methods and Several other topics. Each
employee class will be an instance of that class so for example if I said employee 1 equals
employee and EmPLoyee 2 Equals employee then each of these are [ going ] to be their own
unique instances of the employee class. This is an important distinction because you 'll hear me
talk a lot about instance variables and class variables. When we create methods within a class
they [ receive ] the instance as the first argument Automatically and by convention. We should
call the instance self now. It 's a good idea to stick to convention here and just use self So after
self we can specify what other arguments that we want to Accept so let 's go ahead and accept
the first name the [ last ] name and the pay and I know that we had email , too.
Employee one will be passed in as self and then it will set all [ of ] these attributes. So now that
we have that an it method in place we can go [ ahead ] and delete these manual assignments
that we made down here. We can add some methods to our class to get the full name of an
employee. A common mistake that I see when creating methods is forgetting the self argument
for the instance. So we have to put those parentheses on in order to run that properly so now we
have full advantage of Code reviews here. Now we can also run these methods using the class
name Itself which makes it more obvious of what's going on in the background. We learned how
to create simple classes the difference between a class and an instance of that class. We still
have a lot to cover in future videos , and we 'll be going over more advanced topics.
Corey Schafer
We 'll be learning how to create and use classes within python and how object-oriented
concepts are applied within the language now There 's a lot to cover when working with classes
so I 'm going to break these up into several different videos. We'll learn about inheritance class
and instance variables static methods and class methods and Several other topics. Each
employee class will be an instance of that class so for example if I said employee 1 equals
employee and EmPLoyee 2 Equals employee then each of these are [ going ] to be their own
unique instances of the employee class. This is an important distinction because you 'll hear me
talk a lot about instance variables and class variables. When we create methods within a class
they [ receive ] the instance as the first argument Automatically and by convention. We should
call the instance self now. It 's a good idea to stick to convention here and just use self So after
self we can specify what other arguments that we want to Accept so let 's go ahead and accept
the first name the [ last ] name and the pay and I know that we had email , too.
Employee one will be passed in as self and then it will set all [ of ] these attributes. So now that
we have that an it method in place we can go [ ahead ] and delete these manual assignments
that we made down here. We can add some methods to our class to get the full name of an
employee. A common mistake that I see when creating methods is forgetting the self argument
for the instance. So we have to put those parentheses on in order to run that properly so now we
have full advantage of Code reviews here. Now we can also run these methods using the class
name Itself which makes it more obvious of what's going on in the background. We learned how
to create simple classes the difference between a class and an instance of that class. We still
have a lot to cover in future videos , and we 'll be going over more advanced topics.