Python 2 vs. Python 3 — Important Differences Every Hacker Should Know

Python is commonly touted as one of the best programming languages for beginners to learn, and its straightforward syntax and functionality makes that hard to argue with. But a lot of tutorials still use Python 2, which is outdated now. Python 3 introduces many new features, and it's important to be aware of them going forward, as well as the key differences between Python 3 and its predecessor.


Python 2 was first released in 2000. It improved upon earlier versions of the language and introduced features common to other programming languages such as garbage collection, list comprehension, and Unicode support. Version 2.1 saw a few minor upgrades, and 2.2 was released at the tail end of 2001. Version 2.2 featured type unification, which merged types and classes into a single hierarchy, transforming Python into an object-oriented language.


Versions progressed until Python 2.7, which was to be the last major release until Python 3. Python 2 was officially retired on the first day of 2020. Python 3, first started in 2008, is now the most current option, with version 3.8.3 being the latest update.



Recommended on Amazon: Python Crash Course, 2nd Edition: A Hands-On, Project-Based Introduction to Programming



Print Function


The first and possibly the most noticeable difference in Python 3 is the print function. In Python 2, print could be used with parentheses:


print(‘Hello, world.’)

Or without:


print ‘Hello, world.’

In Python 3, parentheses must be used:


print ‘Hello, world.’

Integer Division


Python 3 also handles the division of integers differently. In version 2, dividing two integers would yield an integer as a result:


Support the originator by clicking the read the rest link below.