1 00:00:00,810 --> 00:00:05,620 Another very distinct feature of Python, that is the Python Act property. 2 00:00:05,970 --> 00:00:09,570 So what is your property, how to use it in python coding? 3 00:00:09,960 --> 00:00:16,860 So let us give you one demonstration, one sample code, its execution, its explanation to describe 4 00:00:16,980 --> 00:00:19,290 what is the property of Python. 5 00:00:20,350 --> 00:00:27,160 The use of property in about Python programming has made the object oriented programming more easy in 6 00:00:27,460 --> 00:00:27,970 Python. 7 00:00:28,330 --> 00:00:32,210 So now let us go into the demonstration of the use of the property. 8 00:00:32,560 --> 00:00:34,210 So here the Web defined one class. 9 00:00:34,210 --> 00:00:36,540 The name of the class is temperature Celsius. 10 00:00:36,550 --> 00:00:37,980 So there is a temp Celsius. 11 00:00:38,260 --> 00:00:43,570 It is having one constructed here and we are passing one parameter temperature with the default argument 12 00:00:43,570 --> 00:00:44,430 is negligible digital. 13 00:00:44,770 --> 00:00:48,950 And here we are having this self underscore temperature, physical temperature. 14 00:00:49,210 --> 00:00:54,100 So this instance biddable underscore temperature underscore indicates that this temperature is under 15 00:00:54,100 --> 00:00:58,720 the microscope and is getting initialized with this input argument, input parameter. 16 00:00:58,720 --> 00:00:59,650 That is the temperature. 17 00:01:00,130 --> 00:01:05,800 And here we are having one method that is a convert to Fahrenheit, which will convert this respective 18 00:01:05,800 --> 00:01:09,710 sun centigrade temperature to the following night here to it having two methods. 19 00:01:09,730 --> 00:01:13,440 One is a guitar method that is a good temperature and another one is a certain method. 20 00:01:13,720 --> 00:01:18,970 There is a set temperature guitar method will bring this text and it will return the respective value 21 00:01:18,970 --> 00:01:19,930 in the temperature. 22 00:01:20,260 --> 00:01:25,270 And the set method will check that the value which will be passed as input argument is less than minus 23 00:01:25,270 --> 00:01:26,530 273 or not. 24 00:01:26,860 --> 00:01:31,150 If it is so, it will raise one error that is evaluated with this respective message. 25 00:01:31,540 --> 00:01:37,240 Otherwise it will bring this message and initialize this temperature with this new value which will 26 00:01:37,240 --> 00:01:38,800 be passed as the input argument. 27 00:01:39,280 --> 00:01:41,550 So now here we are going to have our property. 28 00:01:41,950 --> 00:01:47,220 Property is nothing but one building function which creates and returns the property object. 29 00:01:47,800 --> 00:01:53,880 The basic method signature is about if it is to null and then it is to Deunan. 30 00:01:53,890 --> 00:01:58,930 And then if there is none and Doc is none now, what does it get? 31 00:01:59,270 --> 00:02:05,230 It get is nothing but a function to get the value of the attribute, if it is a function to set the 32 00:02:05,230 --> 00:02:06,340 value of the atiba. 33 00:02:06,340 --> 00:02:07,300 So there is a split. 34 00:02:07,600 --> 00:02:12,070 So if it is a function to get the value of that attribute, that is a greater method. 35 00:02:12,550 --> 00:02:18,670 If it is nothing but a function to set the value of that, there is a certain method if there is a function, 36 00:02:18,670 --> 00:02:24,410 to delete that attribute and doc is nothing but one string, which is like a comment here. 37 00:02:25,000 --> 00:02:28,380 So now it is a particular property has got three methods. 38 00:02:28,390 --> 00:02:32,690 There is a getter setter and delete, so three methods are there. 39 00:02:33,310 --> 00:02:36,730 So here you are defining one and empty property. 40 00:02:36,730 --> 00:02:43,630 So is that impression is a value property and then assigned to get so temperature is equal to temperature, 41 00:02:43,630 --> 00:02:46,180 got getter get temperature. 42 00:02:46,180 --> 00:02:52,690 So get the impression this particular method then we are passing this one as get temperature then assign 43 00:02:52,710 --> 00:02:53,260 upset. 44 00:02:53,260 --> 00:02:55,300 So temperature is equal to temperature. 45 00:02:55,300 --> 00:02:56,910 Grasset set temperature. 46 00:02:57,250 --> 00:03:00,690 So this method will be set as a set temperature. 47 00:03:01,060 --> 00:03:04,630 So now we are going for C is equal to temp Celsius fight. 48 00:03:04,900 --> 00:03:08,820 So C is that new object of the class that is that temp Celsius five. 49 00:03:09,130 --> 00:03:14,590 So this fight will be assigned to this temperature, this particular message will get printed on the 50 00:03:14,590 --> 00:03:19,600 screen and then we're having this one self understocked underscore temperature. 51 00:03:19,600 --> 00:03:22,530 There is a private school temperature is the temperature. 52 00:03:22,930 --> 00:03:24,790 So now let me go for the execution. 53 00:03:24,790 --> 00:03:29,710 You can find that assigning temperature value, that means this constructor has got executed. 54 00:03:30,220 --> 00:03:33,430 So the next one is that print siddharta temperature. 55 00:03:33,730 --> 00:03:39,460 So whenever we are trying to print the value of the temperature, so actually when executing the guitar 56 00:03:39,460 --> 00:03:45,520 method, so getting temperature value, so this particular message should be printed and then it will 57 00:03:45,520 --> 00:03:47,220 return the temperature value. 58 00:03:47,530 --> 00:03:51,670 So as a result of that, as we have, we have called this one from this print method. 59 00:03:51,670 --> 00:03:56,790 So this fight will get printed before that, getting temperature value is also printed. 60 00:03:57,310 --> 00:04:00,240 So now C temperature is equal to 100. 61 00:04:00,250 --> 00:04:02,140 So now this 100 will be assigned. 62 00:04:02,500 --> 00:04:08,920 So we are calling actually the set temperature because we we're setting this temperature so that temperature 63 00:04:09,250 --> 00:04:13,630 will be called by default automatically because it has been set to the property. 64 00:04:13,630 --> 00:04:16,660 There is a built in function and this value will be passed. 65 00:04:16,660 --> 00:04:19,240 And here we are past the value that is 100. 66 00:04:19,510 --> 00:04:20,280 So that's right. 67 00:04:20,570 --> 00:04:25,330 If the value is less and less than minus 273, this condition is not getting through. 68 00:04:25,630 --> 00:04:31,060 So the print setting temperature value, this message will be printed is it has got printed here and 69 00:04:31,060 --> 00:04:33,460 now the value will be assigned to the temperature. 70 00:04:33,850 --> 00:04:40,120 So now when you are again printing this C temperature, so you are getting the we are getting this particular 71 00:04:40,120 --> 00:04:43,240 get temperature method is getting cold. 72 00:04:43,360 --> 00:04:47,980 So getting temperature value and a self-taught underscore temperature will be returned. 73 00:04:48,220 --> 00:04:50,790 And as a result of that, we are getting this one hundred. 74 00:04:51,250 --> 00:04:54,720 So now see, we are making this one as a minus three hundred. 75 00:04:54,730 --> 00:04:57,340 So now what will happen in this case? 76 00:04:57,340 --> 00:05:04,030 The value error will be raised because it is lesser than minus 273, so minus three hundred is less 77 00:05:04,150 --> 00:05:05,650 than 273. 78 00:05:05,650 --> 00:05:09,660 So that is why it is producing that that elevator. 79 00:05:09,790 --> 00:05:13,990 So there is a temperature below minus 273 is not possible. 80 00:05:13,990 --> 00:05:15,860 So that message is getting printed here. 81 00:05:16,390 --> 00:05:19,840 So in this way, we have shown that how this property is getting. 82 00:05:19,870 --> 00:05:20,380 He was here. 83 00:05:20,810 --> 00:05:21,160 OK. 84 00:05:26,770 --> 00:05:35,320 Instead of writing this disrespectful statements, I'm just making the comment I can do the same, just 85 00:05:35,320 --> 00:05:36,860 writing a single statement here. 86 00:05:37,360 --> 00:05:39,440 So there is a temperature is the property. 87 00:05:39,460 --> 00:05:45,940 So the first argument will be if I'm passing that one as a good barometer, the second argument is our 88 00:05:45,940 --> 00:05:46,440 upset. 89 00:05:46,450 --> 00:05:49,140 So we are passing this perimeter that is opposite temperature. 90 00:05:49,540 --> 00:05:55,680 So now this these are the a method is a certain method for if I'm going to get the same output here 91 00:05:56,440 --> 00:05:58,450 now, see if I go on printing. 92 00:05:58,630 --> 00:06:02,320 Princi Daudt underscored underscore. 93 00:06:03,260 --> 00:06:10,460 Did this underscore, underscore, so if you go on printing and finding that I'm fine, I'm finding 94 00:06:10,460 --> 00:06:16,880 one couple is getting printed where this all the instance variable defined in this class is getting 95 00:06:16,880 --> 00:06:18,170 printed with the respective help. 96 00:06:18,200 --> 00:06:19,520 So it is a key value pair. 97 00:06:20,180 --> 00:06:22,940 So just if I go forward to finding out of the one. 98 00:06:24,180 --> 00:06:28,230 Another instance, variables set up with a 500. 99 00:06:29,400 --> 00:06:36,590 If I go to court here, you can find that we're having temperature with a 110 temp with the value 500. 100 00:06:36,930 --> 00:06:44,250 So anybody we bring in some some member variable from this object, actually we're accessing that is 101 00:06:44,250 --> 00:06:48,420 the object named DOT, underscored, underscore, DECT, underscore, underscore. 102 00:06:48,870 --> 00:06:52,770 So if I do not want to print all of them, I can print only the temperature here. 103 00:06:52,770 --> 00:06:54,540 So I shall go for this temperature. 104 00:07:00,710 --> 00:07:03,680 So I can bring only the temperature here, you can find that. 105 00:07:05,320 --> 00:07:11,080 It will bring down the value 100, so if I go on printing only the temp, so that can also be done. 106 00:07:15,870 --> 00:07:17,880 So I think that will bring 500 here. 107 00:07:20,800 --> 00:07:22,910 OK, so that has printed to 500. 108 00:07:23,650 --> 00:07:26,440 OK, now let us concentrate on this property. 109 00:07:26,980 --> 00:07:31,690 So we are having two ways to to have this building function. 110 00:07:31,960 --> 00:07:35,750 So that is that one is the temperature is the property get temperature. 111 00:07:35,770 --> 00:07:37,890 There is a greater than the temperature. 112 00:07:38,230 --> 00:07:39,750 There is a set of metal you can pass. 113 00:07:39,790 --> 00:07:46,450 Otherwise we can make and one empty property object and then we can go for this temperature to get there 114 00:07:46,450 --> 00:07:53,290 and temperature for Setar to give the name of the two parties the name of the greater method and a certain 115 00:07:53,290 --> 00:07:54,350 method respectively. 116 00:07:54,880 --> 00:07:56,720 So let us come to the next example here. 117 00:07:57,160 --> 00:08:01,900 So here you see here, here we are having this in it that is constructed here, the name of the class 118 00:08:01,900 --> 00:08:04,080 in Celsius to perform tonight. 119 00:08:04,090 --> 00:08:08,370 It is converting the Celsius temperature to the far right here. 120 00:08:08,380 --> 00:08:11,770 We're having this at the rate of property is the aderet. 121 00:08:11,920 --> 00:08:13,780 And then we are having this property. 122 00:08:14,110 --> 00:08:19,750 So obviously, this particular this particular after writing this one, we are writing only the temperature. 123 00:08:19,760 --> 00:08:21,490 You see the method name is temperature. 124 00:08:21,850 --> 00:08:28,330 We are not going for the respective GETER setting temperature or temperature methods. 125 00:08:28,750 --> 00:08:33,640 So anybody writing this at the rate of property, that means it is known as the guitar method. 126 00:08:33,910 --> 00:08:39,250 And anybody who are writing this at the rate of temperature Dorsetshire, that means it is the same 127 00:08:39,280 --> 00:08:39,770 method. 128 00:08:39,790 --> 00:08:46,180 So I need not to bother for this set temperature or get temperature will be having the method name as 129 00:08:46,180 --> 00:08:46,990 temperature here. 130 00:08:47,320 --> 00:08:53,230 You see, I didn't do any kind of changes in the respective function bodies, so now C is equal to Celsius 131 00:08:53,230 --> 00:08:53,670 five. 132 00:08:53,800 --> 00:08:55,740 So princi temperature. 133 00:08:55,780 --> 00:08:57,490 So I'm just executing this code here. 134 00:08:57,970 --> 00:09:02,460 So you see here that the method is are getting value is getting printed. 135 00:09:02,490 --> 00:09:04,740 So now you see the C temperature. 136 00:09:04,930 --> 00:09:07,150 That means this particular method is getting printed. 137 00:09:07,150 --> 00:09:09,040 There is a greater method. 138 00:09:09,280 --> 00:09:14,710 And here C, I didn't write anything, anything that is a get underscore or something. 139 00:09:14,860 --> 00:09:17,890 I've given the function name as the temperature. 140 00:09:17,890 --> 00:09:23,920 Only Adelita property will be there, will be downloaded and given at the first and next we are having 141 00:09:23,920 --> 00:09:26,230 the seed or temperature is equal to 100. 142 00:09:26,470 --> 00:09:27,810 So what will happen here. 143 00:09:27,820 --> 00:09:33,850 It is a setting, value is getting cold and then whenever we are printing this print, see the temperature. 144 00:09:34,030 --> 00:09:35,050 Then there's this. 145 00:09:35,050 --> 00:09:39,220 One hundred is getting printed after printing this message getting through. 146 00:09:39,460 --> 00:09:42,610 So here you see here we are calling the property method. 147 00:09:42,610 --> 00:09:48,040 We are just using this at the rate of property and at the rate of temperature, etc.. 148 00:09:48,400 --> 00:09:55,030 So using this particular Adelaida property and other top temperature Dorsetshire, we are just defining 149 00:09:55,030 --> 00:09:57,640 that which is the method and which is the getter method. 150 00:09:57,910 --> 00:10:03,250 So as a result of that, in our object oriented coding, I need not to call the respective functions 151 00:10:03,250 --> 00:10:05,470 by the names I can easily use. 152 00:10:05,680 --> 00:10:11,290 That is a seed temperature for the printing or C the temperature is one hundred for the assigning. 153 00:10:11,530 --> 00:10:14,350 So accordingly, the veterans letter methods are getting cold. 154 00:10:14,800 --> 00:10:22,900 So this is a nice usage of this property method in our python coding to make the object oriented programming 155 00:10:23,050 --> 00:10:24,290 much, much simpler. 156 00:10:24,940 --> 00:10:26,170 Thanks for watching this video.