1 00:00:00,920 --> 00:00:05,120 Pythonesque that assertions can be implemented in bichon. 2 00:00:06,080 --> 00:00:12,560 Assertions are statements that assert our state a fact confidently in our program. 3 00:00:13,040 --> 00:00:19,250 So, for example, while writing a division function, we are confident that this is the that should 4 00:00:19,250 --> 00:00:20,180 not be zero. 5 00:00:20,210 --> 00:00:26,120 We know that division by zero is illegal and we asserted deviser is not equal to zero. 6 00:00:26,720 --> 00:00:33,240 Assertions are simply boolean expressions that checks, if the condition returns, is true or not. 7 00:00:33,680 --> 00:00:39,660 So if it is true, the program does nothing and move to the next line of the code. 8 00:00:39,830 --> 00:00:45,000 However, if it is false, the program stops and throws an error. 9 00:00:45,440 --> 00:00:47,940 So that is a basic principle of assertion. 10 00:00:48,170 --> 00:00:50,540 So let me repeat once again for the clarity. 11 00:00:51,020 --> 00:00:56,420 Assertions are simply boolean expression, so it will return true and false that chix in the condition 12 00:00:56,420 --> 00:01:00,720 return is true or not if it if it is the truth. 13 00:01:00,740 --> 00:01:05,350 The program does nothing and move to the next line of the code if the condition is true. 14 00:01:05,960 --> 00:01:09,900 However, if it is false, the program stops and throws an error. 15 00:01:10,070 --> 00:01:12,680 So that is known as the assertion in Baton. 16 00:01:14,580 --> 00:01:23,100 So it is also a debugging tool as it brings the program on hold, as soon as any error is occurred and 17 00:01:23,100 --> 00:01:26,910 shows on which point of the program, the error has occurred. 18 00:01:27,060 --> 00:01:30,450 So that is a special features of assertion. 19 00:01:31,020 --> 00:01:32,320 So previous code is there. 20 00:01:32,460 --> 00:01:34,320 Now we are having that session condition. 21 00:01:34,530 --> 00:01:38,880 If the condition is true, then the program continue to run. 22 00:01:39,090 --> 00:01:45,840 If the condition is false, then the assertion stops the program and gives us an error and also the 23 00:01:45,840 --> 00:01:49,630 respective point where that particular error has occurred. 24 00:01:49,770 --> 00:01:53,570 So that will be mentioned in the assertion error session later. 25 00:01:54,060 --> 00:02:00,210 So for the better, let us go for one practical demonstration will be showing you that how this assertion 26 00:02:00,420 --> 00:02:02,940 can be implemented in Biton. 27 00:02:03,820 --> 00:02:11,500 We know that assertions are statements that assert our state, in fact, confidently in our program, 28 00:02:11,920 --> 00:02:18,280 for example, while writing a deficient function, you are confident that the deviser should not be 29 00:02:18,280 --> 00:02:18,670 zettl. 30 00:02:18,910 --> 00:02:24,230 In the case, we can prove we can insert one assert device that is not equal to zero. 31 00:02:24,280 --> 00:02:24,950 Accordingly. 32 00:02:25,510 --> 00:02:32,020 So assertions are nothing but simply boolean expressions that checks if the condition returns, true 33 00:02:32,020 --> 00:02:37,120 or not, if it is returning to the program does nothing and move to the next line of code. 34 00:02:37,450 --> 00:02:42,300 And if it returns false, the program stops and throws an error known as the assertion. 35 00:02:42,310 --> 00:02:47,710 Edit so as an example, consider this one where defined one function. 36 00:02:47,710 --> 00:02:52,680 The name of the function is Avijit, which will take this marks the least as input document. 37 00:02:53,200 --> 00:02:54,010 So assert. 38 00:02:54,010 --> 00:02:56,290 Lynn Marks is not called digital. 39 00:02:56,440 --> 00:03:03,400 If the condition is true, that means if the length of this list is not equal, that means the list 40 00:03:03,400 --> 00:03:04,450 is not empty. 41 00:03:04,900 --> 00:03:10,510 If the condition is true, then it will go for the sum of marks by laying up the marks to calculate 42 00:03:10,510 --> 00:03:12,030 the average and that will be returned. 43 00:03:12,730 --> 00:03:19,330 So but if that length of marks is not equal to zero, if the condition is false, then it will produce 44 00:03:19,330 --> 00:03:20,190 the assassinator. 45 00:03:20,770 --> 00:03:26,800 So for the first run, we are making one least available, which is non-empty and we are trying to calculate 46 00:03:26,800 --> 00:03:30,970 the average of them and we are going for the next one with the list is empty. 47 00:03:30,970 --> 00:03:33,680 al-Atassi, what is the outcome we are going to have? 48 00:03:34,570 --> 00:03:39,820 So just see, in the first case we are having this 11 plus 22 plus 33 whole battery. 49 00:03:39,820 --> 00:03:40,980 So I'll be teaching with the value. 50 00:03:40,990 --> 00:03:41,740 Twenty two here. 51 00:03:42,100 --> 00:03:47,980 So average of Mach one is equal to twenty two, so average of one is twenty two is getting executed, 52 00:03:47,980 --> 00:03:49,000 is getting printed. 53 00:03:49,450 --> 00:03:56,350 And now in the second case we are passing this, we initializing this mock one with the null list that 54 00:03:56,350 --> 00:03:57,640 is containing new element. 55 00:03:57,850 --> 00:04:00,820 So the length of this mark one will be zero. 56 00:04:01,150 --> 00:04:04,810 So length of Mach one is not equal, digital recognition will be false. 57 00:04:04,960 --> 00:04:07,840 So it will produce one error known as the assassinator. 58 00:04:08,200 --> 00:04:09,940 So that is known as the assassinator. 59 00:04:10,960 --> 00:04:16,060 So not only the throwing the assassinator, also we can put some error message also, so let us go for 60 00:04:16,060 --> 00:04:16,370 that. 61 00:04:16,930 --> 00:04:22,980 So here to see if the ruling Assad land of the Marxist nautical digital, that list is empty. 62 00:04:23,290 --> 00:04:27,000 So the condition is true that Mr. Length of is not legitimate. 63 00:04:27,010 --> 00:04:29,250 That means the list is not empty. 64 00:04:29,530 --> 00:04:35,080 In that case, it will produce true and it will go to the next line without any interruption authorized 65 00:04:35,080 --> 00:04:40,480 assassinator will be will be obtained and it will be having this message to get printed. 66 00:04:40,510 --> 00:04:42,430 So now let me go to execution. 67 00:04:42,850 --> 00:04:45,930 Matou is not all it is having some value there. 68 00:04:45,940 --> 00:04:47,560 So the average will get calculated. 69 00:04:47,890 --> 00:04:50,380 I think as a mark one it is another list. 70 00:04:50,530 --> 00:04:53,710 So I think that here translation error will be thrown. 71 00:04:53,950 --> 00:04:54,900 So just see here. 72 00:04:55,150 --> 00:04:57,820 So average marks of MC2 is 78. 73 00:04:58,150 --> 00:05:00,230 So 78 is the average marks of marks. 74 00:05:00,820 --> 00:05:05,090 But in the case, in the next one, as a mark, one was having the empty list. 75 00:05:05,470 --> 00:05:08,440 So this particular assassinator has taken place. 76 00:05:08,560 --> 00:05:12,690 And here to see the message has got printed, that is a list is empty. 77 00:05:13,120 --> 00:05:15,150 So there is a message you have given this one. 78 00:05:15,580 --> 00:05:18,190 So this giving this message is optional. 79 00:05:18,200 --> 00:05:24,010 You may or may not give as here we have given and but in the previous example, we didn't give any such 80 00:05:24,010 --> 00:05:24,770 error message. 81 00:05:25,330 --> 00:05:30,520 So I think now that what is a solution in Python, the concept is now getting clear to you. 82 00:05:30,760 --> 00:05:32,050 Thanks for watching this video.