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 the checking account object
that stores data in this specific file
path. And it has these attributes. So it
has this fee, then we have instance
variables. And these are variables that
are defined inside the methods or the
class like filepath here. And these are
accessible by the instance by the
object instance, that is created by that
class. And then we also have something
called class variable. So instance
variable 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.
[No audio]
So our 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, these are 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
jacks_checking account. So I'll replace that,
and that, and that. This is johns_checking account.
[Author typing]
And they also have there
[No audio]
personal storage there. So let's say jack.txt,
and john.txt. So Jack has
$100 and John has $200.
Good. So we need to change
that jacks, jack, and john.
[Author typing]
And if we execute this script now
[Author typing]
we will get two values printed out. So
minus 1 for the statement here,
because the 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 there. He
owes the bank some money. And then John
had 200. So he has a 99 now. So what
I'm trying to say is that these
variables belong only to their object.
But if you try now, jacks_checking.type,
so you want to print that
[Author typing]
print johns_checking.type.
[Author typing]
You'll see that this 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 to you'll rarely have to
pass them in here. Another concept now.
Docstrings. And a docstring is usually
passed as soon as you arrive the class
keywords are just down the class keyword
that provides the explanation of your
class. Let's say this class generates
checking account objects, then you
close that with three quotes.
[No audio]
So what that does is, you know if we print that
out, so we grab one of our object instances, let's say,
johns_checking.__doc and
double underscore again. So print that.
[Author typing]
So as you see, a docstring is used to
provide some information about that
class. So it's good to define the string
when you're writing classes so that
others, if they use your class, and they
can apply this operation here, they can
see what they are classes about. This is
particularly useful when you import in
classes from modules. So when you don't
actually see the code of your class, and
you can do these and you can, you have
access to the docstring of the class.
And then we have a 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. And 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 spatial method. So it's a
constructor. And instantiation. If you
hear about instantiation, there's a
process of creating object instances. So
instances of a class like this is instantiation
of the class, and this one here as well.
[No audio]
You know, inheritance. Now
inheritance is when you create a
subclass out of a base class. And this
subclass shares the methods or 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. I hope you found
this useful. And I'll talk to you either
next lecture. So we're done with this
section, and yeah, see you later.