1
00:00:00,860 --> 00:00:01,230
Hello.

2
00:00:01,250 --> 00:00:01,960
Welcome back.

3
00:00:01,970 --> 00:00:08,180
In this lesson we should take a look at classes and object and this is a very quick introduction to

4
00:00:08,240 --> 00:00:10,700
object orientation in Python.

5
00:00:10,820 --> 00:00:18,470
So objects you can think of objects as an encapsulation of variables and functions into a single entity

6
00:00:18,810 --> 00:00:25,190
so objects are like verb and functions proved to get and combined into a single entity an object to

7
00:00:25,190 --> 00:00:28,190
get the variables and functions from classes.

8
00:00:28,190 --> 00:00:32,430
Classes are essentially templates to create our object.

9
00:00:32,660 --> 00:00:34,290
So let's see how to do this.

10
00:00:34,300 --> 00:00:41,570
I'll close this and create a new project over here for file new and then I'll press control as to save

11
00:00:41,630 --> 00:00:49,880
and then I'll say this is number seven on the school I call this classes and to create a simple class

12
00:00:50,420 --> 00:00:57,140
we can close this one here to create a simple class we can just use the class keyword class and then

13
00:00:57,140 --> 00:00:58,220
the name of the class.

14
00:00:58,220 --> 00:01:07,550
This is simple class and then we put some cool on here we hit enter and then we can give the class a

15
00:01:07,550 --> 00:01:08,380
simple variable.

16
00:01:08,390 --> 00:01:11,880
This rebel the class contains a variable called Hello.

17
00:01:11,960 --> 00:01:16,390
And we can assign a value to hello hello.

18
00:01:16,400 --> 00:01:21,990
The class contains a simple variable known as greeting and we can assign hello to greeting.

19
00:01:22,970 --> 00:01:26,300
So the class contains this variable.

20
00:01:26,300 --> 00:01:30,410
Also we can add a function to the class so we can hit enter.

21
00:01:30,410 --> 00:01:33,040
Come down here an added function and we can say.

22
00:01:33,050 --> 00:01:44,360
Def function 1 and then into brackets here we put self and then we hit enter and then now we can write

23
00:01:44,420 --> 00:01:46,420
what we want this function to do.

24
00:01:46,490 --> 00:01:49,070
We can say the function we want the function to print

25
00:01:52,150 --> 00:01:56,980
this is a simple class like this.

26
00:01:58,560 --> 00:01:59,740
So this is it.

27
00:01:59,740 --> 00:02:02,040
This this is a very simple class.

28
00:02:02,040 --> 00:02:04,200
So now how do we use this class.

29
00:02:04,200 --> 00:02:06,540
We can create objects from this class.

30
00:02:07,990 --> 00:02:09,650
So we can we can come down here.

31
00:02:09,710 --> 00:02:10,410
Let's test it.

32
00:02:10,430 --> 00:02:16,340
So to test the class we come out of the class just like we came out of the function earlier so we can

33
00:02:16,340 --> 00:02:20,990
create a simple we create a variable here on a simple object and simple object.

34
00:02:20,990 --> 00:02:27,700
Here we can assign our class Singapore class right like this.

35
00:02:28,280 --> 00:02:31,710
So let's run this and see what we get.

36
00:02:31,730 --> 00:02:36,080
So first of for this entire section is not to make an expert in Python.

37
00:02:36,080 --> 00:02:42,200
Like I said we just getting used to some of the concepts and basics and then we go straight to DSP.

38
00:02:42,200 --> 00:02:42,860
All of this.

39
00:02:42,860 --> 00:02:44,680
There is much more to it.

40
00:02:44,680 --> 00:02:51,260
This an entire book can be written on Python object orientation but this is just to get you familiar.

41
00:02:51,260 --> 00:02:52,750
You don't need all of that.

42
00:02:52,910 --> 00:02:58,530
I'm giving you just the foundation you need to do your DSP and you've been machine learning stuff so

43
00:02:58,850 --> 00:03:02,040
you will click over here to run the module and save.

44
00:03:02,070 --> 00:03:12,270
Okay and then over here simple object we have this as an object of the class so to access the class

45
00:03:12,270 --> 00:03:15,140
members or to access the content of the class.

46
00:03:15,220 --> 00:03:17,670
Just a simple on the school object

47
00:03:20,710 --> 00:03:30,210
we could assign let's say we want X X because Mexico's simple on this call object

48
00:03:35,110 --> 00:03:41,430
that variable or dot region creating this court or greeting is the verb with the right word is called

49
00:03:41,430 --> 00:03:41,880
greeting.

50
00:03:41,880 --> 00:03:51,100
As you can see as I said simple object dot the ideal is helping me with what the class contains.

51
00:03:51,120 --> 00:03:57,840
So I could either choose the function or degree tense so I just say greeting her and then I'll hit enter.

52
00:03:58,080 --> 00:04:02,130
So if I say X to print x I get hello in the same way.

53
00:04:02,130 --> 00:04:06,110
We can just we can see why.

54
00:04:06,540 --> 00:04:10,940
Because simple on the score object.

55
00:04:11,340 --> 00:04:15,280
This time we can just see the function and a few and see the function is.

56
00:04:15,300 --> 00:04:24,750
If u n c t front 1 and then we hit enter and then this time we don't need to make it print because the

57
00:04:24,750 --> 00:04:26,350
function automatically print.

58
00:04:26,370 --> 00:04:33,810
The reason why we had to say X us in print x is because this hasn't got a print statement but a function

59
00:04:33,870 --> 00:04:39,460
automatically print this and we can create as many objects as we want actually.

60
00:04:39,530 --> 00:04:41,290
So this is just simple objects.

61
00:04:41,310 --> 00:04:53,550
We can say simple on the score object to call a simple class and we've just created another object and

62
00:04:53,590 --> 00:04:56,460
we can see a simple score object to

63
00:05:00,720 --> 00:05:04,410
front one and it's going to print the same thing.

64
00:05:04,430 --> 00:05:07,430
So this is a very very simple class.

65
00:05:07,430 --> 00:05:08,790
We've demonstrated here.

66
00:05:08,840 --> 00:05:13,740
It doesn't do much to just print stuff but you get the idea.

67
00:05:13,760 --> 00:05:19,400
So let's see on that example this one with much more content so let's say would create another class

68
00:05:19,400 --> 00:05:20,440
called computer.

69
00:05:20,450 --> 00:05:27,290
I'm going to come down here and see a class computer and I'll post some cool on here and I can create

70
00:05:27,290 --> 00:05:28,630
the first variable of the class.

71
00:05:28,640 --> 00:05:29,990
Let's call it name.

72
00:05:30,210 --> 00:05:34,270
And this is going to be left empty like this and then hit enter.

73
00:05:34,280 --> 00:05:40,490
We'll create another variable called kind and we can give this this variable a default value which is

74
00:05:40,490 --> 00:05:41,150
laptop.

75
00:05:41,150 --> 00:05:41,800
How about that.

76
00:05:42,470 --> 00:05:51,740
And then we come down here we say color and we'll leave it empty as well and we'll come down here and

77
00:05:51,740 --> 00:05:53,190
we give it a cost.

78
00:05:53,240 --> 00:06:01,190
Let's see another variable cost space this out to improve readability a bit you can give it a cost and

79
00:06:01,280 --> 00:06:07,930
let's give it a default course value of five hundred and we can add a function.

80
00:06:07,940 --> 00:06:10,440
So we've got four variables in our class.

81
00:06:10,610 --> 00:06:17,550
We can at least one function just to make it more fun so we can see the F this is how we create functions

82
00:06:17,580 --> 00:06:19,020
and can give the function a name.

83
00:06:19,130 --> 00:06:22,480
We call this description like this.

84
00:06:22,620 --> 00:06:24,700
We can pass self here.

85
00:06:24,840 --> 00:06:31,610
You can put up some call on here and what we want to do is we want to create a string once grade this

86
00:06:31,610 --> 00:06:32,620
string and this string.

87
00:06:32,660 --> 00:06:40,780
We wanted to say percentages is a percentage as percentages with percentage to F.

88
00:06:40,790 --> 00:06:48,180
And basically what we're going to do is we're going to say laptop we're going to let us going to let

89
00:06:48,180 --> 00:06:50,650
a user assigned a name of the computer.

90
00:06:50,670 --> 00:06:58,300
So if you put Doe here it's going to say Dell s if you put color red.

91
00:06:58,440 --> 00:07:00,720
So Dell is red.

92
00:07:00,930 --> 00:07:12,150
And then if you put kind laptop or that desktop it's going to be Dell is a red desktop with cost basically.

93
00:07:12,150 --> 00:07:13,050
So this is it.

94
00:07:13,050 --> 00:07:15,330
And this a creative way of putting it all together.

95
00:07:15,480 --> 00:07:22,160
Percentage is is a percentage as percentage as with percentage points to.

96
00:07:22,200 --> 00:07:24,750
And this is this one is useful float.

97
00:07:24,750 --> 00:07:28,500
They pointed to efforts with two decimal places.

98
00:07:28,500 --> 00:07:33,900
So then we come over here just like we did earlier when we're seeing the functions we come over here

99
00:07:33,900 --> 00:07:39,060
and we put a percentage here and then we put all the variables we want to assign and we've got a self-taught

100
00:07:39,090 --> 00:07:43,060
name self the color self kind self or cost.

101
00:07:43,080 --> 00:07:50,010
So these are then these variables here where we assign them we come here and then to be added to the

102
00:07:50,010 --> 00:07:51,360
string automatically.

103
00:07:51,360 --> 00:07:52,230
Very simple.

104
00:07:52,430 --> 00:08:03,210
And once that is done we can return the string so we can see return to s desk SDR here description string

105
00:08:03,750 --> 00:08:05,240
and then we can see control.

106
00:08:05,300 --> 00:08:11,700
So let's go to the let's run and test it out with the other window right ID and just put the test code

107
00:08:11,700 --> 00:08:12,370
here.

108
00:08:12,580 --> 00:08:16,570
So click over here and then click on module and let's see.

109
00:08:16,600 --> 00:08:23,070
We want to create a computer class so we can see a computer one because computer like this.

110
00:08:25,770 --> 00:08:30,990
So we've created the object let's say we want to create a computer object it's as simple as computer

111
00:08:30,990 --> 00:08:32,870
one of course computer.

112
00:08:32,880 --> 00:08:36,270
So no no we've created the object the objects known as Computer.

113
00:08:36,270 --> 00:08:45,810
Let's give our computer a name of say computer computer one object a school computer one dot then we

114
00:08:45,810 --> 00:08:55,260
can pass name and let's say we assign something like Dell Latitude it's one of the popular computers

115
00:08:55,380 --> 00:09:08,160
grew up using put Dell Latitude once that's done we've given our computer objects known as Computer

116
00:09:08,160 --> 00:09:08,790
one to name.

117
00:09:09,150 --> 00:09:18,390
How about we give it a color so I can come here and see a computer one dot collar like this and we can

118
00:09:18,390 --> 00:09:21,540
say block like this.

119
00:09:21,690 --> 00:09:27,390
Once that is done we can give it a cost and a kind word denote a kind.

120
00:09:27,390 --> 00:09:29,640
So this that then we've not given the kind yet.

121
00:09:29,670 --> 00:09:33,270
So by default our class says kindness laptop.

122
00:09:33,270 --> 00:09:38,820
If we've not given a kind that default is going to be used if we do not give it cost the default cost

123
00:09:38,820 --> 00:09:39,860
is going to be use.

124
00:09:39,900 --> 00:09:43,770
But let's change the cost here just to you know add some variation.

125
00:09:43,770 --> 00:10:01,410
So I say computer 1 that cost because 800 like this once they stand we can say print computer one dot

126
00:10:01,560 --> 00:10:10,440
description so we access and they function within the within the class computer 1.0 description and

127
00:10:10,530 --> 00:10:15,300
we don't have to pass any argument cost indicated we already passed the argument that supposed to be

128
00:10:15,300 --> 00:10:17,080
printed we hit enter.

129
00:10:17,100 --> 00:10:23,280
And he says Dell Latitude is a black laptop with five hundred dollars.

130
00:10:23,290 --> 00:10:23,970
What happened.

131
00:10:24,370 --> 00:10:24,780
OK.

132
00:10:24,780 --> 00:10:26,430
So we did an assigned cost.

133
00:10:26,430 --> 00:10:29,360
We have a typo here instead of cost.

134
00:10:29,370 --> 00:10:29,990
It's written.

135
00:10:30,010 --> 00:10:30,540
Oh yes.

136
00:10:30,540 --> 00:10:35,200
That's why it's using the default cost so less assigned cost.

137
00:10:35,280 --> 00:10:42,080
Say computer one does cost u s t a course.

138
00:10:42,260 --> 00:10:55,560
Eight hundred 800 hit enter and no less print print into bracket computer one dot description like this

139
00:10:56,130 --> 00:10:57,160
will hit enter.

140
00:10:57,720 --> 00:10:59,980
OK so we have an error here.

141
00:11:00,150 --> 00:11:02,580
Very very simple error.

142
00:11:02,580 --> 00:11:03,700
Just bear with me.

143
00:11:03,840 --> 00:11:06,090
We passed cost as a screen care.

144
00:11:06,340 --> 00:11:08,970
A mistake cost everything else is a string.

145
00:11:09,030 --> 00:11:12,520
So it's easy to get confused though it's easy to forget.

146
00:11:12,660 --> 00:11:13,890
Cost is not a string.

147
00:11:13,980 --> 00:11:20,940
So we don't need this quotation marks around cost so we can come here and see a computer one that cost

148
00:11:21,850 --> 00:11:25,480
because he 200 like this will hit enter and there.

149
00:11:25,490 --> 00:11:32,190
Now we can print Computer 1 dot description

150
00:11:35,040 --> 00:11:40,710
like this and we'll hit until like this and it says Dell Latitude as a black laptop with eight hundred

151
00:11:40,710 --> 00:11:41,560
dollars.

152
00:11:41,580 --> 00:11:44,460
So this is a very simple very straightforward.

153
00:11:44,490 --> 00:11:46,770
This is how to make use of classes.

154
00:11:46,790 --> 00:11:46,990
Yeah.

155
00:11:47,010 --> 00:11:48,360
We just have one object.

156
00:11:48,360 --> 00:11:52,230
We can make 10 object and we do need to create all of them from scratch.

157
00:11:52,230 --> 00:11:53,070
We can have another.

158
00:11:53,070 --> 00:11:56,810
We can create a new computer computer 2 equals MacBook.

159
00:11:56,820 --> 00:11:58,220
Computer to color.

160
00:11:58,240 --> 00:12:02,030
Course wide computer to prize of course 2000.

161
00:12:02,180 --> 00:12:08,610
And we have it do the same thing MacBook as a white laptop worth two thousand dollars.

162
00:12:08,610 --> 00:12:08,840
Yes.

163
00:12:08,850 --> 00:12:15,260
So this is a very simple example for how classes are used and how they behave.

164
00:12:15,360 --> 00:12:16,680
This order is for this lesson.

165
00:12:16,680 --> 00:12:21,760
If you have any questions at all send me a message or leave it in the questions area.

166
00:12:21,780 --> 00:12:22,750
Have a great day.

167
00:12:22,830 --> 00:12:23,190
By.
