1
00:00:00,930 --> 00:00:01,650
Hello, dear friends.

2
00:00:02,550 --> 00:00:06,000
In this lesson, we will learn the constructor function in Python.

3
00:00:08,820 --> 00:00:13,650
Now, if you do recall, we created a class in our previous class.

4
00:00:14,400 --> 00:00:20,100
So with the help of this class, we created new objects, but those objects, attributes and values

5
00:00:20,430 --> 00:00:21,210
are the same.

6
00:00:21,960 --> 00:00:27,090
So what if we want to create different objects with the same attributes, but different values using

7
00:00:27,090 --> 00:00:28,170
the class that we created?

8
00:00:29,220 --> 00:00:33,150
So for this, we can use a special method named in it.

9
00:00:34,440 --> 00:00:36,420
Also called constructor function.

10
00:00:37,560 --> 00:00:41,820
So, first of all, let's have a look at the content of the my own object that we created.

11
00:00:43,920 --> 00:00:45,660
Dear my phone.

12
00:00:50,100 --> 00:00:55,590
And as you can see, some of them we created ourselves, but the rest of them we didn't.

13
00:00:56,190 --> 00:01:01,380
So these methods are specially defined when an object is created by Python.

14
00:01:02,040 --> 00:01:06,960
And if we don't specifically define them, then, well, Python defines them by default.

15
00:01:08,180 --> 00:01:10,430
Now, here we also see the init method.

16
00:01:11,240 --> 00:01:16,490
If we define this method ourselves, we can initialize our objects with different values.

17
00:01:17,950 --> 00:01:23,200
So this method is the first function that's automatically called when creating our objects.

18
00:01:24,790 --> 00:01:30,550
So by defining this method specifically, we can create our objects with different values.

19
00:01:31,030 --> 00:01:35,080
So let's make up an example so that we can better understand this.

20
00:01:36,450 --> 00:01:38,040
Class phone.

21
00:01:39,310 --> 00:01:42,400
Death in it self.

22
00:01:43,720 --> 00:01:44,200
Print.

23
00:01:45,400 --> 00:01:46,780
The function was called.

24
00:01:49,450 --> 00:01:53,290
All right, so when we run this code, we create the phone class.

25
00:01:54,650 --> 00:01:56,930
Now create an object named phone one.

26
00:01:58,190 --> 00:01:58,940
From one.

27
00:01:59,950 --> 00:02:01,120
Equals phone.

28
00:02:03,200 --> 00:02:05,660
And the result is the function was called.

29
00:02:06,850 --> 00:02:09,430
So what does self mean here?

30
00:02:09,520 --> 00:02:09,740
Hmm.

31
00:02:11,110 --> 00:02:17,380
The key word self is a reference to the object when we create it, and it is a parameter that should

32
00:02:17,380 --> 00:02:23,530
be present in our methods in the very first place, so we can use all the properties and methods of

33
00:02:23,530 --> 00:02:25,390
an object through this reference.

34
00:02:26,350 --> 00:02:31,810
So when we create an object, Python automatically sends this reference to the methods itself.

35
00:02:33,690 --> 00:02:36,930
So now let's have a look at some more details to our class.

36
00:02:37,910 --> 00:02:39,210
Class phone.

37
00:02:39,860 --> 00:02:42,560
Deaf in it, self.

38
00:02:42,980 --> 00:02:50,720
Brand model color camera MP HDD Ram platform.

39
00:02:55,890 --> 00:02:58,050
Self-taught brand equals brand.

40
00:02:59,430 --> 00:03:01,650
Self-taught model equals model.

41
00:03:03,110 --> 00:03:05,180
Self-taught color equals color.

42
00:03:08,200 --> 00:03:11,500
Self-taught camera MP equals camera MP.

43
00:03:13,900 --> 00:03:16,870
Self-doubt HDD equals HDD.

44
00:03:19,870 --> 00:03:21,940
Self-doubt rim equals ram.

45
00:03:22,940 --> 00:03:25,400
Self-taught platform equals platform.

46
00:03:28,730 --> 00:03:31,160
Great, so now we can create a new object.

47
00:03:32,430 --> 00:03:35,850
So let's create an object named my phone.

48
00:03:38,020 --> 00:03:41,380
My phone equals phone Huawei.

49
00:03:43,290 --> 00:03:44,910
Mate, twenty pro.

50
00:03:47,460 --> 00:03:50,100
Black 40 MP.

51
00:03:51,060 --> 00:03:53,190
128 GBE.

52
00:03:53,580 --> 00:03:58,020
Six GBE Android nine, dot zero.

53
00:04:00,060 --> 00:04:04,170
And our object has been created, so let's look at my phone attribute.

54
00:04:05,330 --> 00:04:11,630
My phone, Dr. Brandt, the result is warui, my phone, DKC color.

55
00:04:12,910 --> 00:04:14,260
The result is black.

56
00:04:15,990 --> 00:04:19,980
And as you can see, the attributes, values are the same as we define.

57
00:04:21,180 --> 00:04:25,020
All right, so now let's have a look at another object named John's phone.

58
00:04:26,640 --> 00:04:28,980
Now let's look at John's phones attributes.

59
00:04:30,560 --> 00:04:33,350
Apple iPhone X.

60
00:04:34,760 --> 00:04:37,250
Silver, 12 MP.

61
00:04:38,830 --> 00:04:40,570
64 GB.

62
00:04:42,420 --> 00:04:49,230
Three GB Iooss 12. three John's phone got brand.

63
00:04:53,350 --> 00:04:56,860
The result is Apple John's phonecard color.

64
00:04:58,420 --> 00:04:59,560
The result is silver.

65
00:05:01,310 --> 00:05:07,310
So see that we created two different objects with the same attributes, but different values.

66
00:05:07,790 --> 00:05:09,290
So that means we've achieved our goal.

67
00:05:09,650 --> 00:05:17,570
However, I want to talk about one last thing about this topic, and we can also write the init method

68
00:05:17,750 --> 00:05:19,400
with default value.

69
00:05:19,670 --> 00:05:21,410
So let's have a look, see how that's done.

70
00:05:21,680 --> 00:05:22,400
Follow along.

71
00:05:31,810 --> 00:05:34,480
Right, so now let's create another object named Jack's phone.

72
00:05:36,850 --> 00:05:39,130
Jack's phone equals phone.

73
00:05:42,050 --> 00:05:44,540
Zao me am I?

74
00:05:49,250 --> 00:05:49,880
Nine.

75
00:05:51,780 --> 00:05:52,320
Blue.

76
00:05:55,030 --> 00:05:57,040
And that's a look at the attributes.

77
00:05:58,750 --> 00:06:00,460
Jack's phone got brand.

78
00:06:05,620 --> 00:06:06,940
The result is Ayame.

79
00:06:09,630 --> 00:06:11,310
Jack Phonogram.

80
00:06:14,730 --> 00:06:17,100
And the result is no information.

81
00:06:18,310 --> 00:06:19,000
What do you think?

82
00:06:19,420 --> 00:06:23,530
So as you can see, we can create an object using classes.

83
00:06:23,860 --> 00:06:26,770
We don't need to define all the values of our object.

84
00:06:27,460 --> 00:06:33,430
But just because we don't define it, we don't get an error when we create the object, because Python

85
00:06:33,430 --> 00:06:35,470
automatically assigns a value to it.

86
00:06:35,830 --> 00:06:36,220
Cool.

87
00:06:36,430 --> 00:06:41,530
So here the Yassine value obviously is no information, and that's it.

88
00:06:41,950 --> 00:06:46,120
So in this lesson, we learned the constructor function and how to use it.

89
00:06:46,840 --> 00:06:48,580
So I want to see you in the next lesson.

90
00:06:49,150 --> 00:06:52,240
So practice if you need to otherwise have a nice day.
