1 00:00:00,000 --> 00:00:01,000 Friends here our concept is 2 00:00:01,000 --> 00:00:06,000 'destructor' of a Class. See already we know about 3 00:00:06,000 --> 00:00:09,900 'constructor'. A 'constructor' is a special method and that is 4 00:00:09,900 --> 00:00:11,000 called by default 5 00:00:11,000 --> 00:00:13,300 whenever you create an object from a class. 6 00:00:13,900 --> 00:00:16,100 So first, let me show you this. Already we know this. 7 00:00:16,500 --> 00:00:18,500 So let me define a class called 'Person', 8 00:00:18,500 --> 00:00:22,410 [no audio] 9 00:00:22,400 --> 00:00:26,300 then in that I am defining a method called 'init'. You know 10 00:00:26,300 --> 00:00:31,100 that is nothing but 'constructor' of your class, then 'print( 11 00:00:31,400 --> 00:00:33,200 "an object has been created".)' 12 00:00:34,700 --> 00:00:38,200 You know this method will execute by default whenever you 13 00:00:38,200 --> 00:00:39,500 create an object. 14 00:00:40,700 --> 00:00:45,400 from this class. Right. See that. I am creating an object called 15 00:00:45,400 --> 00:00:47,900 'per1', then let me write simply, 16 00:00:47,900 --> 00:00:49,700 [no audio] 17 00:00:49,700 --> 00:00:53,100 and let me run this and see the result. "an object has been created". 18 00:00:54,100 --> 00:00:55,100 That's it. 19 00:00:56,300 --> 00:01:01,300 And because of this advantage, right, we can define 20 00:01:02,500 --> 00:01:07,400 variables or we can call some methods by default in 21 00:01:07,400 --> 00:01:08,700 this initialization method. 22 00:01:09,000 --> 00:01:10,800 Let's say for my 'per1' 23 00:01:10,900 --> 00:01:12,600 I need to assign name and age. 24 00:01:12,700 --> 00:01:15,900 So for that, you don't need to write a separate method. Suppose 25 00:01:15,900 --> 00:01:19,700 if you don't have 'constructor' then suppose name and age, 26 00:01:19,700 --> 00:01:22,900 let me write 'name_age'. Then for this you have to pass 27 00:01:22,900 --> 00:01:26,100 your 'name' and 'age', right. And then you have to write 28 00:01:26,100 --> 00:01:30,200 'self.name=' some 'name', then 'self.age=' 29 00:01:30,200 --> 00:01:33,500 some 'age', then simply write 'return None'. 30 00:01:34,200 --> 00:01:36,900 And to assign your 'name' and 'age' you need to call 31 00:01:36,900 --> 00:01:39,800 from 'per1' 'name_age' method, like 32 00:01:41,400 --> 00:01:46,900 in this way. So after creation of an object, 'per1.name_age', then 33 00:01:46,900 --> 00:01:47,900 you have to pass, 34 00:01:49,300 --> 00:01:50,800 suppose some name, 35 00:01:50,800 --> 00:01:52,800 [no audio] 36 00:01:52,800 --> 00:01:55,400 then let's say some age, in this way. 37 00:01:55,400 --> 00:01:57,300 [no audio] 38 00:01:57,300 --> 00:02:01,300 Right, but because of this advantage, you know by default 39 00:02:01,300 --> 00:02:03,900 initialization method is calling, that's why what I will do 40 00:02:03,900 --> 00:02:08,400 is instead of defining your name and age for your object, 41 00:02:09,199 --> 00:02:12,600 I will write the code here itself and I will delete this 42 00:02:12,600 --> 00:02:17,400 method. Now, I reduced one method to define my age, and I mean 43 00:02:17,500 --> 00:02:21,500 for my 'per1', or for my object, name and age. 44 00:02:23,000 --> 00:02:24,800 Right. Yeah, fine. 45 00:02:24,800 --> 00:02:27,410 [no audio] 46 00:02:27,400 --> 00:02:31,900 Now this initialization method is requiring two variables - name 47 00:02:31,900 --> 00:02:34,500 and age. Now, let me take them as arguments. 48 00:02:34,500 --> 00:02:36,510 [no audio] 49 00:02:36,500 --> 00:02:40,000 And now your 'self' method requires two arguments, right. See 50 00:02:40,000 --> 00:02:44,000 that, in the output error, name and age, 'missing 2 positional 51 00:02:44,000 --> 00:02:45,800 required arguments: 'name' and 'age'.' 52 00:02:46,200 --> 00:02:48,600 That's why while calling, 53 00:02:48,600 --> 00:02:51,600 I mean while creating an object, here itself you have to 54 00:02:51,600 --> 00:02:55,200 pass the arguments which are required for your 55 00:02:55,200 --> 00:02:58,109 [no audio] 56 00:02:58,100 --> 00:03:00,900 initialization method or 'constructor' method. That's it. 57 00:03:00,900 --> 00:03:02,900 [no audio] 58 00:03:02,900 --> 00:03:04,000 Right. That's fine. 59 00:03:04,700 --> 00:03:05,700 Now, just assumed that 60 00:03:06,800 --> 00:03:08,700 you've done your work with your objects, 61 00:03:08,700 --> 00:03:10,459 [no audio] 62 00:03:09,800 --> 00:03:13,300 then I don't want to waste my RAM memory, 63 00:03:13,300 --> 00:03:15,800 then I need to delete my objects from RAM. 64 00:03:15,800 --> 00:03:19,100 Then at the end, suppose you have to write deletion 'per1' 65 00:03:19,100 --> 00:03:22,400 object, or if you create any number of objects, that many 66 00:03:22,400 --> 00:03:23,100 number of objects 67 00:03:23,100 --> 00:03:24,100 you have to delete it. 68 00:03:25,200 --> 00:03:26,800 Right. That's fine. 69 00:03:27,300 --> 00:03:31,500 That's fine. You can delete it manually or explicitly by writing 'del', your 70 00:03:31,500 --> 00:03:36,600 object name. But in Python you don't need to delete objects. 71 00:03:36,600 --> 00:03:38,709 [no audio] 72 00:03:38,700 --> 00:03:41,900 Right. See that first thing, 'destructor'. 73 00:03:42,600 --> 00:03:45,900 Destructor is a method first of all, and that method will 74 00:03:45,900 --> 00:03:48,000 call when an object gets destroyed. 75 00:03:49,300 --> 00:03:54,300 But we don't need to delete an object. Python is having automatic 76 00:03:54,300 --> 00:03:59,700 garbage collection or garbage collector, that will manage 77 00:04:00,100 --> 00:04:04,500 memory automatically. See that. But to understand that whether it 78 00:04:04,500 --> 00:04:05,700 is deleting or not, 79 00:04:05,800 --> 00:04:09,500 there is a predefined 'destructor' method that is called 80 00:04:09,500 --> 00:04:11,100 '__del'. 81 00:04:12,200 --> 00:04:15,400 And be clear, you don't need to write this deletion method, 82 00:04:15,400 --> 00:04:19,500 and don't need to use in your codes, but for interview point 83 00:04:19,500 --> 00:04:22,500 of view you have to know what is the use of deletion method. 84 00:04:22,500 --> 00:04:24,600 [no audio] 85 00:04:24,600 --> 00:04:30,900 First let me write my code, "object has been deleted". 86 00:04:30,900 --> 00:04:33,110 [no audio] 87 00:04:33,100 --> 00:04:38,000 Let me write 'return', simply 'None'. Now see the output. Because 88 00:04:38,000 --> 00:04:41,300 of this object, I mean automatically this initialization method will call, 89 00:04:42,200 --> 00:04:46,000 and because of automatic garbage collector of your Python 90 00:04:46,300 --> 00:04:49,600 once if you've done your work, it will automatically delete. 91 00:04:49,700 --> 00:04:54,400 Whenever your 'per1' object is deleting from your memory, 92 00:04:54,500 --> 00:04:58,600 at that time just it will call automatically deletion method 93 00:04:58,600 --> 00:05:01,200 if you have inside of your code. If you don't have, no problem. 94 00:05:02,700 --> 00:05:05,700 And in this method we have this information that's why it is 95 00:05:05,700 --> 00:05:07,300 printing. So guys 96 00:05:07,300 --> 00:05:11,700 finally you have to know one thing, 'constructor' method will 97 00:05:11,700 --> 00:05:16,100 call by default whenever if you create an object, and deletion 98 00:05:16,100 --> 00:05:21,300 method or 'destructor' method will call by default whenever 99 00:05:21,600 --> 00:05:25,700 an object has been deleted from your memory by your Python, 100 00:05:25,700 --> 00:05:30,600 but not by you. Automatically you'll delete an object. At that time 101 00:05:30,700 --> 00:05:32,200 just to know that whether it is deleting, 102 00:05:32,300 --> 00:05:35,600 or not we are using 'deletion' method. That's it. 103 00:05:37,000 --> 00:05:40,300 Okay. But while writing your codes, you don't need to use 104 00:05:40,300 --> 00:05:44,300 this 'deletion' method. But if you use it's good. Right. But 105 00:05:44,300 --> 00:05:48,000 for interview point of view, it is important simply. Right. 106 00:05:48,200 --> 00:05:50,971 Okay guys, thank you for watching this simple video. 107 00:05:50,971 --> 00:05:53,000 [no audio]