1
00:00:08,190 --> 00:00:17,760
As many other programming languages, Python is also a very good object, orientation, language and

2
00:00:17,760 --> 00:00:19,410
what means object orientation.

3
00:00:19,740 --> 00:00:23,190
This means that also Python can create a custom class.

4
00:00:24,160 --> 00:00:32,730
So we already learned the most famous data types or the most famous classes disordered, the integer

5
00:00:33,360 --> 00:00:34,260
string.

6
00:00:35,470 --> 00:00:44,490
William and so on, OK, in this class are predefined, but sometimes you want to create a type that

7
00:00:44,500 --> 00:00:47,950
is a custom one and really simplify so called.

8
00:00:49,370 --> 00:00:51,410
For example, if you want to create.

9
00:00:52,620 --> 00:00:54,110
Different types of animals.

10
00:00:55,670 --> 00:01:02,300
It is way easier to have a pretty defined class which implements all the methods that are applicable

11
00:01:02,300 --> 00:01:08,750
for exactly animals and all the different colors and breeds and basically different types of animals

12
00:01:08,990 --> 00:01:11,490
that you can find out there.

13
00:01:11,870 --> 00:01:15,280
And this is quite useful when used in programming.

14
00:01:15,290 --> 00:01:20,690
And to be honest, most of the complex and real world codes are object oriented.

15
00:01:21,200 --> 00:01:24,590
But let's see how this works now in our IDE.

16
00:01:25,340 --> 00:01:32,960
So you declare a class by keyword class in Python, so separate class then the name of the class.

17
00:01:32,960 --> 00:01:39,310
In our case, animal is the class who can go out the functions applicable from this class.

18
00:01:39,650 --> 00:01:42,510
For example, what an animal can do.

19
00:01:43,070 --> 00:01:44,490
Well, the animal control.

20
00:01:44,660 --> 00:01:47,590
So I will create a method so def.

21
00:01:48,990 --> 00:01:57,270
Run in then self, and now let's print what is going to happen, and just so here, we're right running.

22
00:01:58,440 --> 00:02:04,610
So when we call this metal for an animal, dismiss the animals running, no, let's create another method.

23
00:02:05,100 --> 00:02:11,940
So T.F. eat and then print eating.

24
00:02:12,840 --> 00:02:13,350
Right.

25
00:02:13,380 --> 00:02:19,350
So this a class of animals and, you know, all the animals can run and eat.

26
00:02:19,350 --> 00:02:22,410
And for that reason, disconcert implemented here.

27
00:02:23,010 --> 00:02:29,700
But now you're creating an animal that have this features or how you're creating an instance of the

28
00:02:29,700 --> 00:02:30,240
class.

29
00:02:30,840 --> 00:02:31,900
It is very simple.

30
00:02:32,070 --> 00:02:36,840
For example, I want to create a dog, so dog will be equal to animal.

31
00:02:37,020 --> 00:02:41,520
OK, this is the same way a certain variable can be integer.

32
00:02:41,520 --> 00:02:47,280
For example, on no, let's say from one to 10, the numbers from 149 in are integers.

33
00:02:47,280 --> 00:02:47,600
Right.

34
00:02:48,540 --> 00:02:51,660
And the dog is of a type animal that's already defined.

35
00:02:51,870 --> 00:03:00,450
So if I write Dog Dot and you can see now when they write the dog dot, they're in the Middle East and

36
00:03:00,450 --> 00:03:03,430
were unavailable because they're available for this class.

37
00:03:03,570 --> 00:03:03,950
Right.

38
00:03:04,320 --> 00:03:07,810
So let's choose the Middle East and just from the cold.

39
00:03:08,040 --> 00:03:12,480
So if I run it, you can see that the dog is sitting at the moment, right.

40
00:03:14,200 --> 00:03:17,720
Now, you can also at some future with this dog.

41
00:03:18,010 --> 00:03:19,630
So if I write a dog Dot.

42
00:03:21,490 --> 00:03:26,710
And then the British will be Podell, OK, and I what all of adult.

43
00:03:28,830 --> 00:03:38,600
Age in the age of the dog could be five years right now if I were to print Dog Dot.

44
00:03:39,770 --> 00:03:47,300
H I will get five for the age of the doc, OK, but do you see something that is not quite right here?

45
00:03:47,600 --> 00:03:53,810
Well, the problem here is that every time that we create a dog outside of this class, we will need

46
00:03:53,810 --> 00:03:55,780
to define dog, dog, breed.

47
00:03:55,790 --> 00:04:02,960
So we are defining a new parameter and then saying that's a poodle or dog to teach in stating that it's

48
00:04:02,960 --> 00:04:05,180
five years old, isn't that better?

49
00:04:05,330 --> 00:04:11,750
If we could have this features inside our class and yes, in Python, you can do that.

50
00:04:12,770 --> 00:04:18,350
And actually the most useful way to do this is by a constructor.

51
00:04:18,560 --> 00:04:20,170
And what constructor is?

52
00:04:20,720 --> 00:04:25,850
Well, it just means that basically when you want to create a dog or any other animal, when you want

53
00:04:25,850 --> 00:04:32,900
to create an animal, you definitely need some parameters that are going to be assigned to this animal.

54
00:04:33,200 --> 00:04:40,910
For example, D.F. and constructor is marked by init or just the initialization.

55
00:04:41,270 --> 00:04:43,430
OK, self cómo.

56
00:04:45,220 --> 00:04:45,910
Breeds.

57
00:04:46,950 --> 00:04:48,780
Colma color.

58
00:04:50,110 --> 00:04:59,260
And then the cycle itself not breeds equal to greed and self-doubt.

59
00:05:00,840 --> 00:05:02,670
Color is equal to color.

60
00:05:02,940 --> 00:05:11,280
OK, so now every user that wants to create an animal first has to declare what is the breed in the

61
00:05:11,280 --> 00:05:12,900
color of this animal?

62
00:05:12,950 --> 00:05:13,410
OK.

63
00:05:14,550 --> 00:05:25,200
So now the creation of the dog will look like this dog equals animal, so class animal inside the briquettes,

64
00:05:25,200 --> 00:05:28,940
it's right for them in the car will be white.

65
00:05:30,260 --> 00:05:39,260
And now if I want to print dot, dot, you're getting great, Cowwarr, I'd run and also dismantlers

66
00:05:39,260 --> 00:05:39,540
here.

67
00:05:39,860 --> 00:05:46,110
So if I would like dog breeds and let's actually add it in the print statement.

68
00:05:46,760 --> 00:05:51,740
So if I run the code now, you can see that we're getting the breed of the dog that was defined once

69
00:05:51,740 --> 00:05:53,770
we declared our dog.

70
00:05:53,960 --> 00:05:54,340
Right.
