Welcome to this tutorial on Python 2 Virgin versus Python 3.
In all of the tutorials I'm going to demonstrate the examples on Python 3 but I would like to bring
this topic up because there's a lot of confusion among beginners on which version to start off with
and also hesitation in the Python community about switching to Python 3.
The python to point all was gone was released in 2000 and the latest version there's two point seven
which was released in 2010 and spurred the code Python team the python two point seven is slated to
reach in the fly in the year 2020.
That means there will be absolutely no more support from the code Python team even for security.
Update coming to Python three point all this was released in 2008 and its latest version is three point
six.
Released in 2016 Python three point or is fundamentally different to previous Python releases because
it is the first Python release that is not compatible with the old divisions programmers usually don't
need to worry about minor updates.
Say for example from Python two point six to two point seven as they usually only change the internal
workings of Python.
And this doesn't require programmers to change their syntax but the change between Python two point
seven that does the final version of Python 2 and Python 3 on ore is much more significant because the
code that worked in Python two point seven may need to be written in a different way to work in Python
3 point 0.
So if you're just picking up a language I recommend you to learn python 3 as its support will continue
well into the future and is being used extensively and also it is not difficult to go back and learn
the differences between the two languages.
That is two point seven and three.
If you need to use two point seven at some point in the future next.
Python 3 has better unicode support in python 2 strings are stored as ASCII by default whereas in Python
3 takes J strings are Unicode by default and Unicode is more versatile than ASCII.
That's because unicode strings can store foreign language letters Roman letters and numerous symbols
emojis etc. offering us more choices since so computers can understand only numbers the ASCII code is
a numerical representation of a character such as E odd at and the table yard contains all 128 ASCII
characters in decimal Octave.
Hexadecimal plot meant coming to the unicode format Unicode is a versatile and robust character encoding
that supports a word one like twenty eight thousand characters across contemporary and historic strips
and symbols at.
And if you want to store Strings as unicode in Python 2.
In that case you can add a u just before the string.
Here we see some of the symbols that are supported by unicode.
We will now see how we can display the unicode characters in python 2 as well as Python 3 versions.
So for that let's create a Jupiter notebook one in Python two equation.
So I've created one notebook in python 2 version and and now one to create another book notebook in
Python 3 version in Python 3 say for example I would like to display the copyright symbol and for that
I will define a string is D 1 and assign the code for the symbol copyright and that symbol is zero Z
or a nine.
In order to encode this particular code for copy died in a format known as UTF 8 we need to append this
code with the characters backslash.
You will print this string losing the print function and execute so your code as you can see the display.
The copyright symbol in Python 3.
Now let's go to Python 2 and do the scene.
So here is a python not to note book or let define a novice during your.
And here is the code for the copyright symbol.
It's 0 0 a 9.
And as we have discussed before if you want to store Strings as unicode in python 2 We need to add you
in front of the code.
Also as we have discussed before not to encode this particular symbol in know the format UTF 8 we need
to append the string the code with backslash you now we will print the string
as to do so Python 3 uses Unicode by default which says programmers extra development time and we can
easily type and display more characters directly in to our program.
And if you would like the Python 3 code to be backwards compatible with Python 2 we can keep you before
the string.
There any python 3 non book.
So in case you want to if you want the code in Python 3 to be backwards compatible with Python to weaken
you keep the U before D string Python 2 has and Python 3 have different libraries since Python 3 is
the future.
Many of today's developers are creating libraries strictly for use with Python 3.
Similarly many older libraries built for Python 2 are not forward compatible next.
Python 3 has improved integer division in Python 2.
If you write a number without the need digit after the decimal point it's it round your calculation
down to the nearest whole number.
Say for example we want to do wide the number 5 by 2 and then execute.
As you can see here the question is do the result has been rounded to the nearest whole number.
If you want the exact answer of 2.5 in that case you can drive floating point number.
See for example flight point or divided by two and then execute.
So here you have the expected result of 2.5 coming to Python 3.
If you divide the same number 5 with two then execute we get the expected result of 2.5 without having
to worry about adding those extra zeros next.
By then 2 and Python 3 have different print statements and taxes.
This is only a syntactical difference in Python 3 but it is a function say for example I print a statement
the little one since print as a function in Python 3.
I need to enclose this string in parenthesis and then execute in Python 2.
Yet in the python tone more book.
Print as a statement.
So if I say and Hello What.
This works perfectly fine without dependencies in Python 2.
No coming back to it.
Python 3 notebook so for example we give the print function without the parent this is let's see what
happens.
Code has been interrupted by the interpreter but the syntax Edward saying that the parent this is missing
in the print function
so we have discussed the differences between the two versions.
Next we will discuss about the future module.
Python 3.
Introduce some Python two incompatible keywords and creatures that can be imported via the inbuilt future
module in Python to say for example if we want the Python 3 versions integer division behavior in Python
2.
We can imported via the future module in order to import the division from the future module.
This is how you do from underscored on the school future on this school on the school.
Import division.
So now if you tried to do the integer division in python 2 you'll get the expected result.
And this is about the differences between the Python 2 and Python 3 versions.