1
00:00:00,000 --> 00:00:04,799
Hello again, and in this lecture I would
like to make sure you know the

2
00:00:04,799 --> 00:00:10,320
terminology of object-oriented
programming in Python, so now we have the

3
00:00:10,320 --> 00:00:17,580
class which is this blueprint here or
you can call it a prototype that defines

4
00:00:17,580 --> 00:00:23,609
the characteristics of an object that is
about to be created, so that's the class.

5
00:00:23,609 --> 00:00:29,640
And then we have the object instance,
or simply the object, so this here is

6
00:00:29,640 --> 00:00:36,870
an object, so a checking account
object that stores data in this specific

7
00:00:36,870 --> 00:00:43,860
file path and it has this attribute so
it has this fee. Then we have instance

8
00:00:43,860 --> 00:00:50,309
variables, and these are variables that
are defined inside the methods of the

9
00:00:50,309 --> 00:00:57,059
class like file path here, and these are
accessible by the instance, so by the object

10
00:00:57,059 --> 00:01:03,120
instance that is created by that class.
Then we also have something called class

11
00:01:03,120 --> 00:01:08,820
variable, so instance variables, and class
variables. Now we didn't create a class

12
00:01:08,820 --> 00:01:13,680
variable in any of the previous lectures
so I'll go ahead and create one now.

13
00:01:13,680 --> 00:01:18,240
Let's create one for our checking
account, so that would be something like

14
00:01:18,240 --> 00:01:30,090
let's say type equals to checking, so
a class variable is declared outside of

15
00:01:30,090 --> 00:01:36,360
the methods of that class, and class
variables are shared by all the

16
00:01:36,360 --> 00:01:42,240
instances of a class, so instance variables
are shared by only the object instance.

17
00:01:42,240 --> 00:01:48,360
For instance let me explain that. Here
this is one of our object instances,

18
00:01:48,360 --> 00:01:54,390
so we only have one object instance here,
but we could have more, so I'll copy this

19
00:01:54,390 --> 00:02:00,290
and create another object instance here.
And I'll call this, let's say this is

20
00:02:00,290 --> 00:02:12,640
Jack's checking account, so I'll replace
that, and that, and that. This is

21
00:02:12,640 --> 00:02:28,250
John's checking account, and they also
have their personal storage there, so let's

22
00:02:28,250 --> 00:02:40,370
say Jack dot txt and John dot txt.
So Jack has 100 dollars, and John has

23
00:02:40,370 --> 00:02:47,680
200 dollars. Good, so we need to
change that, Jack's, Jack,

24
00:02:47,680 --> 00:03:05,780
and John, and if we execute this
script now, we will get two values

25
00:03:05,780 --> 00:03:15,470
printed out, so minus 1 for this statement
here because Jack had, so he had $100

26
00:03:15,470 --> 00:03:21,890
there, but when he transferred 100 and
then minus the fee of $1 and then he

27
00:03:21,890 --> 00:03:29,709
ended up with minus 1 dollar there.
He owns the bank some money, and then

28
00:03:29,709 --> 00:03:37,220
John had 200 so he has 99 now.
So what I'm trying to say is that these

29
00:03:37,220 --> 00:03:46,840
variables belong only to their object,
but if you try now Jack's checking dot

30
00:03:46,840 --> 00:04:03,739
type, so you want to print that, print
John's checking dot type. You'll see

31
00:04:03,739 --> 00:04:09,980
that this a class variable is shared by
all the instances of that class.

32
00:04:09,980 --> 00:04:14,600
So that's the difference between class
and instance variables. Class variables

33
00:04:14,600 --> 00:04:19,640
are rarely used,
so you'll really have to pass them in here.

34
00:04:19,640 --> 00:04:27,970
Another concept now, doc strings
and a doc stirring is usually passed

35
00:04:27,970 --> 00:04:33,910
as soon as you ride the class keyword,
so just down the class keyword and that

36
00:04:33,910 --> 00:04:41,259
provides the explanation of your class.
Let's say this class generates checking

37
00:04:41,259 --> 00:04:53,400
account object, and then you close that
with three quotes, so what that does is

38
00:04:53,400 --> 00:05:01,449
you know if we print that out, so we grab
one of our object instances, let's say

39
00:05:01,449 --> 00:05:13,889
John's checking dot double underscore doc
and double under score again, so print that.

40
00:05:19,199 --> 00:05:24,520
So as you see a doc string is used to
provide some information about that

41
00:05:24,520 --> 00:05:29,680
class, so it's good to define this string
when you're writing classes so that

42
00:05:29,680 --> 00:05:35,740
others if they use your class and they
can apply this operation here and they can

43
00:05:35,740 --> 00:05:40,630
see what your class is about. This is
particularly useful when you're

44
00:05:40,630 --> 00:05:46,000
importing classes from modules, so when
you don't actually see the code of your

45
00:05:46,000 --> 00:05:52,780
class, and you can do this and you can,
you have access to the doc string of the

46
00:05:52,780 --> 00:05:59,340
class, and then we have the concept
of data members which actually is referred

47
00:05:59,340 --> 00:06:06,970
to class variables or instance variables.
So this is a data member, and this also is

48
00:06:06,970 --> 00:06:13,680
a data member as well. Then we have the
constructor which was this init function.

49
00:06:13,680 --> 00:06:20,199
And as you know the init function, so the
constructor constructs your class. Then

50
00:06:20,199 --> 00:06:26,259
you have class methods that you apply to
your object instance, so transfer is a

51
00:06:26,259 --> 00:06:31,570
class method, so this is also a method
but it's a special method, so it's

52
00:06:31,570 --> 00:06:36,400
a constructor, and instantiation if you
hear about instantiation that is the

53
00:06:36,400 --> 00:06:42,550
process of creating object
instances, so instances of a class like

54
00:06:42,550 --> 00:06:49,960
this is instantiation of the class,
and this one here as well, and you know

55
00:06:49,960 --> 00:06:55,390
inheritance now. Inheritance is when you
create a subclass out of a base class.

56
00:06:55,390 --> 00:07:02,800
And this subclass shares the methods of
the base class plus it has its own

57
00:07:02,800 --> 00:07:09,520
methods that are specific to that
subclass. Sometimes you also hear about

58
00:07:09,520 --> 00:07:17,410
attributes and attributes are these one
here, so when you access these instance

59
00:07:17,410 --> 00:07:24,220
variables, or even, so class variables,
or even instance variables, you can say

60
00:07:24,220 --> 00:07:30,220
you're accessing attributes of your
class instance, so of your object. And yeah,

61
00:07:30,220 --> 00:07:35,830
that's about the vocabulary of object-oriented
programming in Python.

62
00:07:35,830 --> 00:07:40,960
I really believe I have given you
a solid understanding of object-oriented

63
00:07:40,960 --> 00:07:47,080
programming, and creating classes and
objects and so on. If you still find

64
00:07:47,080 --> 00:07:51,490
something confusing
you can either rewatch your videos

65
00:07:51,490 --> 00:07:55,210
because I know object-oriented
programming is a bit tricky, but you can

66
00:07:55,210 --> 00:08:00,790
even ask questions, and I'll make my best
to explain things that are not yet

67
00:08:00,790 --> 00:08:07,060
clear to you, and I hope you find this
useful, and I'll talk you in the next

68
00:08:07,060 --> 00:08:11,410
lectures, so we're done with this
section, and yeah, see you later.

