1
00:00:00,740 --> 00:00:01,550
Hey, welcome back.

2
00:00:01,550 --> 00:00:05,900
So far, you learned about instance variables and instance methods.

3
00:00:05,900 --> 00:00:11,600
And these two can also be categorized in the instance attributes category.

4
00:00:11,600 --> 00:00:15,740
So these are attributes of an instance.

5
00:00:16,520 --> 00:00:19,440
So instance variables and instance methods.

6
00:00:19,460 --> 00:00:24,420
Then you learned about class variables and class methods.

7
00:00:24,440 --> 00:00:28,520
These two are also known as class attributes.

8
00:00:28,970 --> 00:00:29,210
Right.

9
00:00:29,210 --> 00:00:33,410
So we have instance attributes and class attributes.

10
00:00:34,410 --> 00:00:39,630
So attributes can be either variables or methods, right?

11
00:00:39,660 --> 00:00:45,120
Now, in this video you will learn about properties, actually instance properties.

12
00:00:45,120 --> 00:00:51,510
So a property is a method which behaves like a variable.

13
00:00:52,450 --> 00:00:53,620
You'll see how.

14
00:00:53,800 --> 00:00:56,980
Let's go down to the reservation ticket class.

15
00:00:57,580 --> 00:01:03,220
We have two instance methods here currently in it and generate.

16
00:01:03,430 --> 00:01:09,430
And we will add another method which is going to be a property.

17
00:01:09,430 --> 00:01:13,630
So a special instance method called a property.

18
00:01:14,590 --> 00:01:23,950
So let's say that maybe the customer, they enter their name in lowercase letters and maybe they enter

19
00:01:23,950 --> 00:01:27,850
some unnecessary spaces when they type in their name.

20
00:01:28,220 --> 00:01:36,610
And so we want to clean that out, to remove the spaces and capitalize the first and the last name of

21
00:01:36,610 --> 00:01:37,600
the customer.

22
00:01:39,160 --> 00:01:44,430
A good way to do that would be inside a property and I'll explain you why.

23
00:01:44,440 --> 00:01:47,290
So let's create a.

24
00:01:47,880 --> 00:01:51,240
A method is called the customer name.

25
00:01:51,720 --> 00:01:56,640
You see, this is not a verb because this is a property.

26
00:01:57,240 --> 00:02:00,950
It makes more sense to be more like a variable name.

27
00:02:00,960 --> 00:02:04,050
I'll explain why when you call that property.

28
00:02:05,510 --> 00:02:09,770
And then you see a local variable.

29
00:02:09,770 --> 00:02:14,120
So this is just a variable which has meaning inside this particular method.

30
00:02:14,150 --> 00:02:19,430
This will be equal to self, that customer name that strip.

31
00:02:19,610 --> 00:02:23,210
So the strip method removes any spaces.

32
00:02:23,210 --> 00:02:31,400
So let's say that the customer name is John Smith with some space at the end.

33
00:02:33,380 --> 00:02:37,520
What we're doing here is customer name that strip and that will return.

34
00:02:37,520 --> 00:02:39,500
John Smith without the space.

35
00:02:42,460 --> 00:02:43,090
Right.

36
00:02:43,200 --> 00:02:45,790
And then again, we say name is equal to name.

37
00:02:45,820 --> 00:02:47,920
Dot title.

38
00:02:49,740 --> 00:02:53,520
So name will be John Smith without space and.

39
00:02:54,830 --> 00:03:05,210
Basically the second line we're doing this, so we get John Smith cleaned out with Capsulated in J and

40
00:03:05,210 --> 00:03:08,330
S, and then we return name.

41
00:03:09,250 --> 00:03:19,600
Now this looks just like a normal instance method to make this an actual property you use property decorator.

42
00:03:21,280 --> 00:03:22,620
I know you're still confused.

43
00:03:22,630 --> 00:03:24,130
What's the point here?

44
00:03:24,160 --> 00:03:25,200
Well, you'll see.

45
00:03:25,210 --> 00:03:26,570
What's the point there?

46
00:03:26,590 --> 00:03:34,620
So let's create a ticket is equal to reservation ticket.

47
00:03:34,630 --> 00:03:38,080
That's the name of the class which has this property.

48
00:03:38,530 --> 00:03:38,930
Right.

49
00:03:38,980 --> 00:03:40,150
Reservation ticket.

50
00:03:40,180 --> 00:03:43,060
It needs a customer name and hotel object.

51
00:03:44,800 --> 00:03:45,640
Customer name.

52
00:03:45,640 --> 00:03:52,000
Let's say the customer entered the name John Smith with the space and with lowercase letters.

53
00:03:53,860 --> 00:03:55,540
And hotel.

54
00:03:57,210 --> 00:03:58,230
Object.

55
00:04:01,020 --> 00:04:04,080
Is equal to a hotel instance.

56
00:04:04,080 --> 00:04:05,610
Hotel one, for example.

57
00:04:08,170 --> 00:04:14,140
Now with ticket dot the customer name.

58
00:04:15,730 --> 00:04:21,579
You can access the returned value of the customer name.

59
00:04:22,210 --> 00:04:23,650
Let's print this out.

60
00:04:23,680 --> 00:04:28,150
Print that and see what we get as output.

61
00:04:28,930 --> 00:04:32,410
So we get John Smith with Capital J and Capital SE.

62
00:04:32,440 --> 00:04:37,030
Now that means we can use the customer name.

63
00:04:40,500 --> 00:04:49,380
Insights here as well to generate the tickets or self the customer name, right.

64
00:04:51,650 --> 00:04:55,070
And so the benefit of this is that you don't need to call this.

65
00:04:55,070 --> 00:04:58,750
That's what makes this a property right.

66
00:04:58,910 --> 00:05:00,820
It behaves like a variable.

67
00:05:00,830 --> 00:05:09,740
It's defined as a method, but this decorator makes it behave like a variable.

68
00:05:10,790 --> 00:05:13,670
So let's call the generate method.

69
00:05:15,270 --> 00:05:19,410
Tickets generate generate doesn't take any.

70
00:05:20,290 --> 00:05:22,120
Arguments other than self.

71
00:05:22,210 --> 00:05:29,920
So we should see the output with John Smith printed out on the ticket.

72
00:05:32,500 --> 00:05:35,190
And so that's about properties.

73
00:05:35,200 --> 00:05:38,080
So you should use a property.

74
00:05:38,880 --> 00:05:49,170
When you think that the value this method returns looks more like an instance variable, but the value

75
00:05:49,170 --> 00:05:50,790
needs some processing.

76
00:05:50,790 --> 00:05:56,400
So you could also place these lines in the init function.

77
00:05:56,400 --> 00:06:04,860
So to modify the customer name by stripping it out and applying a title method, but that would be too

78
00:06:04,860 --> 00:06:08,040
much for the init function for the init method.

79
00:06:08,040 --> 00:06:15,090
So it makes more sense to create a property and then you can just access the customer name.

80
00:06:16,400 --> 00:06:20,420
As if it was a normal instance variable.

81
00:06:20,420 --> 00:06:29,580
So the benefit is that you keep this code enclosed inside a method, so that keeps things more organized.

82
00:06:29,600 --> 00:06:31,430
And yeah, that's about properties.

83
00:06:31,430 --> 00:06:34,820
And we have some more videos, so I'll see you in the next ones.

