The New Year Brings The Official End Of Python2 Support
After a long and successful history, Python2 has finally reached its end of life (EOL) for support from the Python development team. This means that the Python development team will no longer provide features or security patches to the Python2 project. Due to large levels of community support, from amateur developers to seasoned veterans, Python2 lived for nearly a decade; with a life spanning from Jul. 2010 to Jan. 2020.
Python3 saw its first release in Dec. 2008, boasting a large set of new features and optimizations. In order to convince any philistines who are still hesitant on their conversion to Python3, I thought it prudent to point out some of the best improvements between these two major Python versions.
The first feature is string formatting! In Python2 string formatting was unintuitive and relied on positional function arguments. Python3, on the other hand features a new string type called an fstring. Comparing the Python2 code and the Python3 code we can see how clean and compact the Python3 code is in comparison.
A comparison between printing in Python2 and Python3
Another feature that you may have already noticed is that the print statement has been transitioned to being a function in Python3, rather than a keyword. To skip the nitty-gritty details, this increases consistency throughout the language and maintains the idea that reserved keywords are actually traditionally reserved keywords. This keeps python consistent with the overall programming community and allows programmers coming from other backgrounds to understand python code more clearly and quickly than before.
A very important and rarely appreciated feature is string encoding differences between the two versions. Python2 is prone to bugs when handling unicode strings (like emojis). It is an absolute nightmare. Take my word for it. Conversely, with Python3 no attention needs to be paid to the encoding of any string. All unicode strings are supported and nearly 100 percent of use cases are supported.
My favorite change is how division is handled by default. All division is automatically casted to a float. This allows very intuitive code behavior for new and old programmers alike.
Division comparison between Python2 and Python3
Even though division between two integers historically produces an integer, it is often a source of error and confusion for programmers to suddenly discover that everything they divide is being rounded down. The beautiful thing is that in any case where you want the result of a division operation to be rounded down in Python3, you can simply use the “//” operator. This causes the new version to produce the same result as the retired Python2.
Overall, Python3 offers wonderful improvements over Python2 and it is well worth any programmer’s time to make the transition.