Python 2 vs Python 3: Key Differences and When to Use Each
print() as a function and better Unicode support, while Python 2 uses print as a statement and has different integer division behavior. Python 3 is recommended for new projects because Python 2 is no longer maintained.Quick Comparison
Here is a quick side-by-side comparison of Python 2 and Python 3 on key features.
| Feature | Python 2 | Python 3 |
|---|---|---|
| Print statement | print 'Hello' | print('Hello') |
| Integer division | Truncates result: 3 / 2 == 1 | True division: 3 / 2 == 1.5 |
| Unicode support | Separate str and unicode types | All strings are Unicode by default |
| Library support | Many older libraries only support Python 2 | Most modern libraries support Python 3 only |
| End of life | Officially unsupported since 2020 | Actively maintained and improved |
Key Differences
Python 3 introduced several important changes to make the language cleaner and more consistent. One major change is that print became a function, so you must use parentheses like print('Hello'). In contrast, Python 2 uses print as a statement without parentheses.
Another key difference is how division works. In Python 2, dividing two integers truncates the decimal part (e.g., 3 / 2 == 1), which can cause bugs. Python 3 fixes this by making division always return a float (e.g., 3 / 2 == 1.5), matching most people's expectations.
Unicode handling is also improved in Python 3. All strings are Unicode by default, making it easier to work with international text. In Python 2, you had to use a separate unicode type explicitly, which was confusing and error-prone.
Code Comparison
Here is a simple example showing how to print a message and divide numbers in Python 2.
print 'Hello from Python 2' print 3 / 2
Python 3 Equivalent
The same example in Python 3 uses the print function and true division.
print('Hello from Python 3') print(3 / 2)
When to Use Which
Choose Python 3 for all new projects because it is actively maintained, supports modern features, and has better Unicode and division behavior. Most libraries now support only Python 3.
Use Python 2 only if you must maintain or run legacy code that has not been updated, but plan to upgrade soon since Python 2 is no longer supported.