1 00:00:00,630 --> 00:00:09,630 In this tutorial we will talk about two more magic methods the SDR method and the art EPR method the 2 00:00:09,630 --> 00:00:19,860 SDR method is call using the built in function SD art or when we are using the print function in Python 3 00:00:21,440 --> 00:00:30,890 and this method the SDR method is used to compute the informal string representation of an object coming 4 00:00:30,890 --> 00:00:33,440 to the RTP add method. 5 00:00:33,440 --> 00:00:43,490 This method is called using the built in function IDE E.P. at and it is used to compute the official 6 00:00:43,490 --> 00:00:54,880 string representation of an object the SDR and the odd add method must return a String object. 7 00:00:54,950 --> 00:01:03,170 Let us now see how these two methods work or function to the SDR function. 8 00:01:03,170 --> 00:01:12,530 I'm going to pass an integer execute and this has returned a string object the number one enclosed in 9 00:01:12,530 --> 00:01:13,070 court. 10 00:01:13,100 --> 00:01:15,330 So this is a string. 11 00:01:15,360 --> 00:01:28,490 Now let us pass a string to the R E P R method let's pass the integer 1 and it has returned a String 12 00:01:28,580 --> 00:01:38,430 object as you can see now we will pass a string to the SDR method. 13 00:01:40,660 --> 00:01:42,500 Let's pass the string hello. 14 00:01:42,990 --> 00:01:54,260 And it tested it on a string object let us parse the same string the same string to the odd EPA method 15 00:01:58,290 --> 00:02:09,470 this time the string Halo has been dropped on enclosed in double quotes by the IDP at Metro. 16 00:02:09,740 --> 00:02:19,290 So what is the difference between the output that we see here that is from the SDR method and the output 17 00:02:19,290 --> 00:02:24,780 here from the RTP method as talked earlier. 18 00:02:24,810 --> 00:02:36,990 The SDR method returns an informal representation of a string so the SDR method is used to print a nicely 19 00:02:36,990 --> 00:02:48,300 printable string representation of an object and the SDR method displays the just the content of these 20 00:02:48,300 --> 00:02:53,130 string coming to the ADP add method. 21 00:02:53,130 --> 00:03:03,000 This computes the official string representation of an object or a literal representation of a string 22 00:03:03,620 --> 00:03:13,360 the string that you see in the output can be evaluated by the Python interpreter into a string object. 23 00:03:13,740 --> 00:03:26,610 The SDR method is used for the users so that the output is a human readable string coming to the IDP 24 00:03:26,610 --> 00:03:27,440 out method. 25 00:03:27,450 --> 00:03:33,890 It is supposed to include detailed information about an object content. 26 00:03:34,320 --> 00:03:44,220 So this method is for the developers and it is used for debugging so the representation should be information 27 00:03:44,340 --> 00:03:45,310 rich. 28 00:03:45,660 --> 00:03:55,290 In a previous tutorial we have created a class card and this class defined these structured object object 29 00:03:55,560 --> 00:04:04,250 which is basically a list of items and then we have created two instances of the card. 30 00:04:04,470 --> 00:04:16,890 Class got one and got to let us now display these two cards using the SD card and the IDE EPR method 31 00:04:16,890 --> 00:04:19,610 and see how the added present. 32 00:04:19,980 --> 00:04:31,580 Let us pass the object got one two D string method and this is how it is represented. 33 00:04:31,580 --> 00:04:36,380 This is the string representation of the instance Scott one 34 00:04:39,580 --> 00:04:42,410 what about RTP add method. 35 00:04:42,460 --> 00:04:46,110 How does it represent a good instance. 36 00:04:46,330 --> 00:04:47,830 Got one. 37 00:04:48,340 --> 00:04:57,700 And this is how it is represented using the odd API meter and the output basically says that this instance 38 00:04:57,700 --> 00:05:07,930 got one is an object of the class card and this particular memory address when we display it when we 39 00:05:07,930 --> 00:05:13,390 want to string representation of our word instance of the instance got one. 40 00:05:13,540 --> 00:05:18,280 We actually want to see the list of items in this particular card. 41 00:05:19,120 --> 00:05:21,270 But this is not happening. 42 00:05:21,370 --> 00:05:28,370 That is because we have not defined how to format the card object. 43 00:05:28,420 --> 00:05:39,930 These two methods SD odd and the IDP add methods are not defined in a very user defined class got so 44 00:05:39,960 --> 00:05:49,530 it only has the init method as you can see here so let us now define two methods in this class. 45 00:05:49,530 --> 00:06:00,310 God is d odd and the IDP our method and get a string representation of our God object. 46 00:06:00,450 --> 00:06:10,320 I want to define the SDR method in such a way that whenever I display the instance of the card plus 47 00:06:10,950 --> 00:06:21,890 got one card do using a print function the output should only display the items in the list. 48 00:06:22,500 --> 00:06:32,340 So we will define another function in this class card and this is called underscored underscored underscored 49 00:06:32,430 --> 00:06:41,970 underscored the double underscored SDR method which is the magic method and this should return a String 50 00:06:42,210 --> 00:06:45,290 object in order to format the string. 51 00:06:45,290 --> 00:06:51,660 I'm going to use the default mat method so Indigo curly braces. 52 00:06:51,660 --> 00:07:01,040 We are going to parse the list of items so dart forward might still dart items. 53 00:07:01,040 --> 00:07:10,080 We have defined the SDR method in our word class got in order to have an informal representation of 54 00:07:10,140 --> 00:07:11,540 the card object. 55 00:07:12,560 --> 00:07:21,770 Now we will also define the double underscored at EPA method in our class got no to compute the official 56 00:07:21,770 --> 00:07:24,790 representation or discard object. 57 00:07:25,710 --> 00:07:28,570 So let's see how we can do that. 58 00:07:28,620 --> 00:07:33,600 This is how we have created the instance of the cat object. 59 00:07:33,630 --> 00:07:44,900 We have parsed a list of items to the cut class now using IDP odd method when we display the instances 60 00:07:44,960 --> 00:07:46,730 of the card object. 61 00:07:46,730 --> 00:07:52,070 This is how we want the object to be represented. 62 00:07:53,080 --> 00:08:04,590 So when we display the card object using the odd EPR method this is how we want the object to be represented. 63 00:08:04,690 --> 00:08:08,440 Before defining the IDP method in our class. 64 00:08:08,500 --> 00:08:13,450 This is how the object is represented in the official string representation. 65 00:08:13,450 --> 00:08:18,760 Now we will define the IDP ad meter in our class card. 66 00:08:18,940 --> 00:08:21,030 So this is the class card. 67 00:08:21,070 --> 00:08:26,070 We will be playing the double underscored IDP ad method. 68 00:08:26,200 --> 00:08:36,070 The odd EPR method should return a String object and the output should look something like this. 69 00:08:36,160 --> 00:08:45,890 So using the format method we are going to pass the list of items in the curly braces here. 70 00:08:46,060 --> 00:08:53,720 So let us add these two methods in the class card and then execute. 71 00:08:53,830 --> 00:08:57,130 So we have added these two methods. 72 00:08:57,140 --> 00:09:01,720 The double underscore the SDR and the double underscored RTP and methods. 73 00:09:01,990 --> 00:09:11,990 In the class card and now let us display these two instances let us pass the instance card to one. 74 00:09:12,000 --> 00:09:19,240 Now when you execute the SDR method by passing the instance of the card object. 75 00:09:20,130 --> 00:09:21,750 So now you see 76 00:09:24,480 --> 00:09:31,230 this has done an informal representation of human readable format. 77 00:09:31,230 --> 00:09:42,800 All the card object now letters call the odd EPR method on the card object or the instance card one. 78 00:09:42,810 --> 00:09:50,050 So this time it has done a string that can be directly executed. 79 00:09:50,430 --> 00:09:57,820 And if you observe carefully this object looks exactly like how the instance was created. 80 00:09:59,010 --> 00:10:06,030 And this brings us to the end of the topic SD card and the IDB added methods which are the magic of 81 00:10:06,030 --> 00:10:07,460 the Dunbar methods.