Hello again, and in this lecture I would like to make sure you know the
terminology of object-oriented programming in Python, so now we have the
class which is this blueprint here or you can call it a prototype that defines
the characteristics of an object that is about to be created, so that's the class.
And then we have the object instance, or simply the object, so this here is
an object, so a checking account object that stores data in this specific
file path and it has this attribute so it has this fee. Then we have instance
variables, and these are variables that are defined inside the methods of the
class like file path here, and these are accessible by the instance, so by the object
instance that is created by that class. Then we also have something called class
variable, so instance variables, and class variables. Now we didn't create a class
variable in any of the previous lectures so I'll go ahead and create one now.
Let's create one for our checking account, so that would be something like
let's say type equals to checking, so a class variable is declared outside of
the methods of that class, and class variables are shared by all the
instances of a class, so instance variables are shared by only the object instance.
For instance let me explain that. Here this is one of our object instances,
so we only have one object instance here, but we could have more, so I'll copy this
and create another object instance here. And I'll call this, let's say this is
Jack's checking account, so I'll replace that, and that, and that. This is
John's checking account, and they also have their personal storage there, so let's
say Jack dot txt and John dot txt. So Jack has 100 dollars, and John has
200 dollars. Good, so we need to change that, Jack's, Jack,
and John, and if we execute this script now, we will get two values
printed out, so minus 1 for this statement here because Jack had, so he had $100
there, but when he transferred 100 and then minus the fee of $1 and then he
ended up with minus 1 dollar there. He owns the bank some money, and then
John had 200 so he has 99 now. So what I'm trying to say is that these
variables belong only to their object, but if you try now Jack's checking dot
type, so you want to print that, print John's checking dot type. You'll see
that this a class variable is shared by all the instances of that class.
So that's the difference between class and instance variables. Class variables
are rarely used, so you'll really have to pass them in here.
Another concept now, doc strings and a doc stirring is usually passed
as soon as you ride the class keyword, so just down the class keyword and that
provides the explanation of your class. Let's say this class generates checking
account object, and then you close that with three quotes, so what that does is
you know if we print that out, so we grab one of our object instances, let's say
John's checking dot double underscore doc and double under score again, so print that.
So as you see a doc string is used to provide some information about that
class, so it's good to define this string when you're writing classes so that
others if they use your class and they can apply this operation here and they can
see what your class is about. This is particularly useful when you're
importing classes from modules, so when you don't actually see the code of your
class, and you can do this and you can, you have access to the doc string of the
class, and then we have the concept of data members which actually is referred
to class variables or instance variables. So this is a data member, and this also is
a data member as well. Then we have the constructor which was this init function.
And as you know the init function, so the constructor constructs your class. Then
you have class methods that you apply to your object instance, so transfer is a
class method, so this is also a method but it's a special method, so it's
a constructor, and instantiation if you hear about instantiation that is the
process of creating object instances, so instances of a class like
this is instantiation of the class, and this one here as well, and you know
inheritance now. Inheritance is when you create a subclass out of a base class.
And this subclass shares the methods of the base class plus it has its own
methods that are specific to that subclass. Sometimes you also hear about
attributes and attributes are these one here, so when you access these instance
variables, or even, so class variables, or even instance variables, you can say
you're accessing attributes of your class instance, so of your object. And yeah,
that's about the vocabulary of object-oriented programming in Python.
I really believe I have given you a solid understanding of object-oriented
programming, and creating classes and objects and so on. If you still find
something confusing you can either rewatch your videos
because I know object-oriented programming is a bit tricky, but you can
even ask questions, and I'll make my best to explain things that are not yet
clear to you, and I hope you find this useful, and I'll talk you in the next
lectures, so we're done with this section, and yeah, see you later.