1 00:00:00,870 --> 00:00:04,900 Comparisons are an important feature of programming. 2 00:00:04,900 --> 00:00:08,680 When it comes to comparing two objects you've created, 3 00:00:08,680 --> 00:00:10,730 Python will need to know what to do. 4 00:00:12,120 --> 00:00:20,460 For example, using our car class, how would two instances compare? 5 00:00:21,580 --> 00:00:24,300 Let's just stick with equals right now. 6 00:00:24,300 --> 00:00:28,150 What would make two car instances equal? 7 00:00:28,150 --> 00:00:33,465 Is it matching makes and models or matching makes, models and years? 8 00:00:34,860 --> 00:00:37,310 Let's just keep it to makes and models. 9 00:00:37,310 --> 00:00:42,219 We'll need to add the Dunder method that handles equal comparisons to our 10 00:00:42,219 --> 00:00:44,527 car class, it's Dunder equals. 11 00:00:56,308 --> 00:01:00,788 It takes self and other which is the thing you're comparing it to. 12 00:01:02,702 --> 00:01:07,830 Inside the method, let's check if the make and models are equal and return it. 13 00:01:24,925 --> 00:01:26,661 This will give us the true or 14 00:01:26,661 --> 00:01:30,920 false boolean value the comparison is looking for. 15 00:01:30,920 --> 00:01:33,610 Let's test it out with an if statement. 16 00:01:33,610 --> 00:01:35,870 If one instance is equal to another, 17 00:01:35,870 --> 00:01:39,260 we can print out a message saying they're equal. 18 00:01:39,260 --> 00:01:42,638 Otherwise, print out a message saying they're not equal. 19 00:02:04,035 --> 00:02:12,390 So with our two instances right now, we get not equal when the file is run. 20 00:02:12,390 --> 00:02:15,854 But if we switch out the make and model to be equal, 21 00:02:22,512 --> 00:02:23,431 Run it again. 22 00:02:29,649 --> 00:02:30,730 We get equal. 23 00:02:31,780 --> 00:02:36,850 Try this out on your own by creating a new class, adding an equal method, and 24 00:02:36,850 --> 00:02:38,750 testing it out with some comparisons.