1 00:00:00,270 --> 00:00:10,610 Let us now discuss how the arithmetic Operation Division is performed in python 2 was John buses Python 2 00:00:10,650 --> 00:00:21,840 3 classic division the classic division is the default division operator behavior in python 2 wasn't 3 00:00:22,260 --> 00:00:36,190 as well as in today's programming languages such as Java and C C++ so when presented with integers opera 4 00:00:36,200 --> 00:00:46,580 and classic division truncate D decimal places and returned an integer when given a pair of floating 5 00:00:46,580 --> 00:00:53,990 point operations it returns actual floating point question. 6 00:00:54,080 --> 00:01:06,350 So in python 2 was shown in python 2 was shown when you divide 5 by 2 which are both integers. 7 00:01:06,350 --> 00:01:20,640 The result would be 2 but if you divide 5 dot all which is a floating point number that 2 The result 8 00:01:20,820 --> 00:01:24,560 would be too darn fine. 9 00:01:24,570 --> 00:01:35,060 So here to have opened the Jupiter notebook and I am now working on the Python 2 was in the notebook 10 00:01:35,070 --> 00:01:40,350 document is currently connected to the kernel Python 2. 11 00:01:41,610 --> 00:01:54,020 So let us divide 5 by 2 and execute the same so as you can see classic division has truncated the decimal 12 00:01:54,020 --> 00:01:54,710 place. 13 00:01:54,710 --> 00:01:57,880 Returning an integer. 14 00:01:57,970 --> 00:02:03,810 Now let us divide 5 dot or by 2. 15 00:02:04,020 --> 00:02:13,140 And in this case the actual floating point question has been written next true division true division 16 00:02:13,140 --> 00:02:20,400 is where the result is always the ideal floating point question regardless of the operant type. 17 00:02:21,060 --> 00:02:27,810 And this is the D5 division operation in any python 3 releases. 18 00:02:27,950 --> 00:02:43,950 In true division when you do Y 5 by 2 The result would be to dot 5 when you divide the floating by number 19 00:02:43,950 --> 00:02:47,390 5 dot or by the integer 2. 20 00:02:47,400 --> 00:02:59,550 The result would be 2.5 regardless of the operant type whether it is an integer or a floating point 21 00:02:59,640 --> 00:03:00,630 number. 22 00:03:00,660 --> 00:03:04,960 The result is always deal floating point question. 23 00:03:05,140 --> 00:03:17,560 OK in order to demonstrate true division I have open another new notebook and this time the kernel is 24 00:03:17,890 --> 00:03:28,760 Python 3 so let's divide 5 the integer 5 by 2 in Python 3. 25 00:03:28,800 --> 00:03:39,260 The answer is 2.5 if we go to a bed or floating point values. 26 00:03:39,420 --> 00:03:49,810 The answer or the quotient is always a floating by number using flawed division began get an integer 27 00:03:49,810 --> 00:03:59,700 present that is by discarding a need fractional reserve and this can be done using the new division 28 00:03:59,760 --> 00:04:09,150 operator which always truncate diffraction and drowns it to the next smallest whole number towards the 29 00:04:09,150 --> 00:04:15,350 left on the number line regardless of the opera and numeric types. 30 00:04:15,390 --> 00:04:30,180 So if you divide one by two using the flawed division the question would be zero because flawed division 31 00:04:30,190 --> 00:04:41,720 truncate the fractional part and it round the question to the next hole numbered toward the left of 32 00:04:41,720 --> 00:04:42,890 the number line. 33 00:04:43,280 --> 00:04:51,550 So instead of zero dark 5 the question would be 0 next. 34 00:04:51,710 --> 00:05:03,740 If we divide the floating by number one dot all using float division to dot or the result would be zero 35 00:05:03,860 --> 00:05:09,780 dark zero so it returns a floor next. 36 00:05:10,180 --> 00:05:21,100 If we do Y minus one by two using flawed division the answer would be minus 1. 37 00:05:21,430 --> 00:05:31,240 The output in this case instead of minus zero point five it would be truncated to minus one because 38 00:05:31,330 --> 00:05:35,120 negatives move left on the number line. 39 00:05:35,200 --> 00:05:43,540 So let us check the flow division in the Python 3 notebook. 40 00:05:44,050 --> 00:05:57,940 So one door or divided by two using flawed division would give me zero dot zero whereas if we give a 41 00:05:57,980 --> 00:06:02,150 minus a negative number so minus 1. 42 00:06:02,150 --> 00:06:05,270 This should be minus 1. 43 00:06:05,300 --> 00:06:17,150 We have just discussed that in Python 2 the D5 division is the classic or the old division and the flawed 44 00:06:17,160 --> 00:06:28,030 division is only available in Python 3 and if you want to use the flawed division functionality in Python 45 00:06:28,030 --> 00:06:28,730 2. 46 00:06:28,900 --> 00:06:32,710 In that case you need to use the future module. 47 00:06:32,890 --> 00:06:43,880 The future module allows us to import Python 3 functionality in python 2 the floor division functionality 48 00:06:43,910 --> 00:06:49,990 is available in Python 3 version but not in Python 2. 49 00:06:50,150 --> 00:06:59,780 So in order to allow us to use the functionality that is mandatory in future Python versions such as 50 00:06:59,780 --> 00:07:11,060 Python 3 we can use the statement we can use the future module which allows us to import Python 3 functionality 51 00:07:11,210 --> 00:07:12,650 in Python 2. 52 00:07:13,490 --> 00:07:20,840 So in here is the statement from underscored underscored future underscore underscore. 53 00:07:21,470 --> 00:07:23,110 Import division. 54 00:07:23,300 --> 00:07:32,010 So from the future module we are importing the division functionality so let's execute this code. 55 00:07:32,100 --> 00:07:44,760 Now if you perform flawed division in python 2 The question would be truncated when you divide one dot 56 00:07:45,690 --> 00:07:53,800 or by two using flawed division instead of returning 0 ORDER BY THE quotient would be truncated to zero 57 00:07:53,800 --> 00:07:56,990 dot zero which is a floating point number. 58 00:07:57,090 --> 00:08:04,770 Say for example if you divide a negative number minus one by two using flawed division the result would 59 00:08:04,770 --> 00:08:09,320 be minus 1 instead of minus zero dot fly.