1 00:00:02,600 --> 00:00:09,000 Welcome to this tutorial on Python 2 Virgin versus Python 3. 2 00:00:09,020 --> 00:00:17,720 In all of the tutorials I'm going to demonstrate the examples on Python 3 but I would like to bring 3 00:00:17,720 --> 00:00:25,190 this topic up because there's a lot of confusion among beginners on which version to start off with 4 00:00:25,970 --> 00:00:33,020 and also hesitation in the Python community about switching to Python 3. 5 00:00:33,020 --> 00:00:42,230 The python to point all was gone was released in 2000 and the latest version there's two point seven 6 00:00:42,920 --> 00:00:55,420 which was released in 2010 and spurred the code Python team the python two point seven is slated to 7 00:00:55,420 --> 00:00:59,200 reach in the fly in the year 2020. 8 00:00:59,200 --> 00:01:07,250 That means there will be absolutely no more support from the code Python team even for security. 9 00:01:07,270 --> 00:01:18,310 Update coming to Python three point all this was released in 2008 and its latest version is three point 10 00:01:18,310 --> 00:01:18,950 six. 11 00:01:19,060 --> 00:01:29,530 Released in 2016 Python three point or is fundamentally different to previous Python releases because 12 00:01:29,530 --> 00:01:37,030 it is the first Python release that is not compatible with the old divisions programmers usually don't 13 00:01:37,030 --> 00:01:39,580 need to worry about minor updates. 14 00:01:39,610 --> 00:01:47,050 Say for example from Python two point six to two point seven as they usually only change the internal 15 00:01:47,050 --> 00:01:48,550 workings of Python. 16 00:01:48,970 --> 00:01:58,120 And this doesn't require programmers to change their syntax but the change between Python two point 17 00:01:58,120 --> 00:02:07,900 seven that does the final version of Python 2 and Python 3 on ore is much more significant because the 18 00:02:07,900 --> 00:02:15,160 code that worked in Python two point seven may need to be written in a different way to work in Python 19 00:02:15,210 --> 00:02:16,580 3 point 0. 20 00:02:16,710 --> 00:02:24,400 So if you're just picking up a language I recommend you to learn python 3 as its support will continue 21 00:02:24,400 --> 00:02:32,200 well into the future and is being used extensively and also it is not difficult to go back and learn 22 00:02:32,200 --> 00:02:35,600 the differences between the two languages. 23 00:02:35,620 --> 00:02:38,150 That is two point seven and three. 24 00:02:38,170 --> 00:02:43,480 If you need to use two point seven at some point in the future next. 25 00:02:43,480 --> 00:02:54,310 Python 3 has better unicode support in python 2 strings are stored as ASCII by default whereas in Python 26 00:02:54,310 --> 00:03:04,640 3 takes J strings are Unicode by default and Unicode is more versatile than ASCII. 27 00:03:04,640 --> 00:03:12,400 That's because unicode strings can store foreign language letters Roman letters and numerous symbols 28 00:03:12,620 --> 00:03:23,630 emojis etc. offering us more choices since so computers can understand only numbers the ASCII code is 29 00:03:23,720 --> 00:03:34,700 a numerical representation of a character such as E odd at and the table yard contains all 128 ASCII 30 00:03:34,700 --> 00:03:38,340 characters in decimal Octave. 31 00:03:39,450 --> 00:03:51,240 Hexadecimal plot meant coming to the unicode format Unicode is a versatile and robust character encoding 32 00:03:51,720 --> 00:03:59,370 that supports a word one like twenty eight thousand characters across contemporary and historic strips 33 00:03:59,460 --> 00:04:01,280 and symbols at. 34 00:04:01,490 --> 00:04:06,110 And if you want to store Strings as unicode in Python 2. 35 00:04:06,350 --> 00:04:10,610 In that case you can add a u just before the string. 36 00:04:10,610 --> 00:04:16,320 Here we see some of the symbols that are supported by unicode. 37 00:04:16,430 --> 00:04:25,190 We will now see how we can display the unicode characters in python 2 as well as Python 3 versions. 38 00:04:25,190 --> 00:04:33,450 So for that let's create a Jupiter notebook one in Python two equation. 39 00:04:33,450 --> 00:04:43,110 So I've created one notebook in python 2 version and and now one to create another book notebook in 40 00:04:43,680 --> 00:04:53,910 Python 3 version in Python 3 say for example I would like to display the copyright symbol and for that 41 00:04:54,000 --> 00:05:10,640 I will define a string is D 1 and assign the code for the symbol copyright and that symbol is zero Z 42 00:05:10,640 --> 00:05:13,570 or a nine. 43 00:05:13,720 --> 00:05:24,130 In order to encode this particular code for copy died in a format known as UTF 8 we need to append this 44 00:05:24,130 --> 00:05:28,390 code with the characters backslash. 45 00:05:28,720 --> 00:05:40,010 You will print this string losing the print function and execute so your code as you can see the display. 46 00:05:40,020 --> 00:05:42,590 The copyright symbol in Python 3. 47 00:05:42,610 --> 00:05:46,830 Now let's go to Python 2 and do the scene. 48 00:05:46,840 --> 00:05:54,920 So here is a python not to note book or let define a novice during your. 49 00:05:55,150 --> 00:06:02,380 And here is the code for the copyright symbol. 50 00:06:02,390 --> 00:06:06,240 It's 0 0 a 9. 51 00:06:06,240 --> 00:06:14,690 And as we have discussed before if you want to store Strings as unicode in python 2 We need to add you 52 00:06:14,740 --> 00:06:16,530 in front of the code. 53 00:06:16,530 --> 00:06:25,560 Also as we have discussed before not to encode this particular symbol in know the format UTF 8 we need 54 00:06:25,560 --> 00:06:35,740 to append the string the code with backslash you now we will print the string 55 00:06:38,820 --> 00:06:48,370 as to do so Python 3 uses Unicode by default which says programmers extra development time and we can 56 00:06:48,400 --> 00:06:54,040 easily type and display more characters directly in to our program. 57 00:06:54,040 --> 00:07:04,690 And if you would like the Python 3 code to be backwards compatible with Python 2 we can keep you before 58 00:07:04,690 --> 00:07:05,880 the string. 59 00:07:06,050 --> 00:07:07,860 There any python 3 non book. 60 00:07:08,130 --> 00:07:16,140 So in case you want to if you want the code in Python 3 to be backwards compatible with Python to weaken 61 00:07:17,420 --> 00:07:28,970 you keep the U before D string Python 2 has and Python 3 have different libraries since Python 3 is 62 00:07:28,970 --> 00:07:29,780 the future. 63 00:07:29,810 --> 00:07:36,410 Many of today's developers are creating libraries strictly for use with Python 3. 64 00:07:36,410 --> 00:07:44,640 Similarly many older libraries built for Python 2 are not forward compatible next. 65 00:07:44,670 --> 00:07:50,980 Python 3 has improved integer division in Python 2. 66 00:07:51,030 --> 00:07:57,630 If you write a number without the need digit after the decimal point it's it round your calculation 67 00:07:57,630 --> 00:07:59,530 down to the nearest whole number. 68 00:07:59,700 --> 00:08:08,620 Say for example we want to do wide the number 5 by 2 and then execute. 69 00:08:09,170 --> 00:08:17,070 As you can see here the question is do the result has been rounded to the nearest whole number. 70 00:08:18,290 --> 00:08:26,920 If you want the exact answer of 2.5 in that case you can drive floating point number. 71 00:08:26,920 --> 00:08:32,330 See for example flight point or divided by two and then execute. 72 00:08:32,720 --> 00:08:39,940 So here you have the expected result of 2.5 coming to Python 3. 73 00:08:39,990 --> 00:08:49,260 If you divide the same number 5 with two then execute we get the expected result of 2.5 without having 74 00:08:49,260 --> 00:08:53,600 to worry about adding those extra zeros next. 75 00:08:53,610 --> 00:08:58,560 By then 2 and Python 3 have different print statements and taxes. 76 00:08:58,560 --> 00:09:09,240 This is only a syntactical difference in Python 3 but it is a function say for example I print a statement 77 00:09:09,750 --> 00:09:13,580 the little one since print as a function in Python 3. 78 00:09:13,590 --> 00:09:21,420 I need to enclose this string in parenthesis and then execute in Python 2. 79 00:09:21,640 --> 00:09:24,830 Yet in the python tone more book. 80 00:09:24,960 --> 00:09:27,270 Print as a statement. 81 00:09:27,270 --> 00:09:32,570 So if I say and Hello What. 82 00:09:33,190 --> 00:09:37,290 This works perfectly fine without dependencies in Python 2. 83 00:09:37,370 --> 00:09:38,470 No coming back to it. 84 00:09:38,470 --> 00:09:47,020 Python 3 notebook so for example we give the print function without the parent this is let's see what 85 00:09:47,020 --> 00:09:48,490 happens. 86 00:09:48,610 --> 00:09:57,400 Code has been interrupted by the interpreter but the syntax Edward saying that the parent this is missing 87 00:09:57,430 --> 00:09:58,810 in the print function 88 00:10:01,660 --> 00:10:06,790 so we have discussed the differences between the two versions. 89 00:10:06,790 --> 00:10:09,880 Next we will discuss about the future module. 90 00:10:09,880 --> 00:10:10,930 Python 3. 91 00:10:10,930 --> 00:10:19,180 Introduce some Python two incompatible keywords and creatures that can be imported via the inbuilt future 92 00:10:19,180 --> 00:10:26,740 module in Python to say for example if we want the Python 3 versions integer division behavior in Python 93 00:10:26,740 --> 00:10:27,430 2. 94 00:10:27,530 --> 00:10:36,160 We can imported via the future module in order to import the division from the future module. 95 00:10:36,160 --> 00:10:46,650 This is how you do from underscored on the school future on this school on the school. 96 00:10:46,840 --> 00:10:50,350 Import division. 97 00:10:50,370 --> 00:11:00,380 So now if you tried to do the integer division in python 2 you'll get the expected result. 98 00:11:00,610 --> 00:11:06,580 And this is about the differences between the Python 2 and Python 3 versions.