80

I have learned that Python 3 is not backwards compatible.

Will it not affect a lot of applications using older versions of Python?

How did the developers of Python 3 not think it was absolutely necessary to make it backwards compatible?

Michael Currie
  • 13,721
  • 9
  • 42
  • 58
neelmeg
  • 2,459
  • 6
  • 34
  • 46
  • 5
    Of course it won't affect them, they're run under Python 2. – Wooble Jan 30 '12 at 16:14
  • 3
    @Wooble I came across this discussion because I _Googled_ "Is python 3 backwards compatible?" and it was the top result. I realize the StackOverflow mantra is that questions should be answerable rather than subjective. So, I wonder if this question were titled "**Is python 3 backwards compatible?**" vs "**Why is Python 3.0 not backward compatible?**", do you think the community would consider un-closing it ? – blong Jul 23 '15 at 15:34
  • @blong: maybe, but you'd probably have to rewrite the question as well. – Wooble Jul 23 '15 at 16:08
  • @Wooble I think you're right. Initially, I was going to change my mind completely (in agreement with you). However, after I thought about it a bit more, I think this could be helpful to a newcomer. Do you think it would be too invasive of the OP's question to consider changing the question a bit further? – blong Jul 23 '15 at 16:26
  • Nope, it wouldnt be. – neelmeg Feb 22 '16 at 02:35

1 Answers1

73

Is Python 3.0 backward-compatible and why?

Python 3.0 implements a lot of very useful features and breaks backward compatibility. It does it on purpose, so the great features can be implemented even despite the fact Python 2.x code may not work correctly under Python 3.x.

So, basically, Python 3.0 is not backward-compatible on purpose. Thanks to that, you can benefit from a whole new set of features. It is even called "Python 3000" or "Python 3K".

From "What's new in Python 3.0" (available here):

Python 3.0, compared to 2.6. Python 3.0, also known as “Python 3000” or “Py3K”, is the first ever intentionally backwards incompatible Python release. There are more changes than in a typical release, and more that are important for all Python users. Nevertheless, after digesting the changes, you’ll find that Python really hasn’t changed all that much – by and large, we’re mostly fixing well-known annoyances and warts, and removing a lot of old cruft.

Python features new in 3.0, breaking backward compatibility

Some of the most notable features that may be considered as breaking backward compatibility, but improving the language at the same time, are:

  • print is now a function, not a statement, and using it as statement will result in an error,
  • various functions & methods now return an iterator or view instead of list, which makes iterating through their results more memory-efficient (you do not need to store the whole list of results in the memory),
  • cmp argument for sorting functions like sorted() and list.sort() is no longer supported, and should be replaced by key argument,
  • int is now the same as Python 2.x's long, which makes number processing less complex,
  • / operator is now an operator for true division by default (you can still use // for floor division),
  • text in Python 3.x is now Unicode by default,
  • True, False and None are now reserved words (so you are not able to do True, False = False, True,
  • changed usage of metaclass,
  • exceptions are required to be derived from BaseException, must be raised & caught differently than in Python 2.x,
  • and a lot more other changes, making Python more readable, consistent & explicit,
Tadeck
  • 132,510
  • 28
  • 152
  • 198
  • 2
    It is important to clarify that Python 3.x is not an upgrade or what follows after Python 2.x, but it's another branch. – juliomalegria Jan 30 '12 at 16:25
  • 5
    @julio.alegria: Could you elaborate on that? Actually Python 3.x is meant to replace Python 2.x, and as stated within "[_What's new in Python 2.7_](http://docs.python.org/dev/whatsnew/2.7.html)": "_Python 2.7 is planned to be the last of the 2.x releases, so we worked on making it a good release for the long term. To help with porting to Python 3, several new features from the Python 3.x series have been included in 2.7._". – Tadeck Jan 30 '12 at 16:42
  • You're both right and wrong. Python 2.7 is indeed the last Python 2.x release (because now they're going to "*focus their future efforts on the Python 3.x*"). **But**, this doesn't mean (at all) that "*Python 3.x is meant to replace Python 2.x*", as you can see, they haven't mention that anywhere in your link. Otherwise, why caring about making a long term release (2.7)? Get what I say? – juliomalegria Jan 30 '12 at 16:52
  • 1
    @julio.alegria: You may be right. Could you give any sources supporting that ("_this doesn't mean (at all) that Python 3.x is meant to replace Python 2.x_")? I mean: is there any comment from Python core team (maybe Guido Van Rossum?) supporting that? – Tadeck Jan 30 '12 at 16:56
  • 1
    I'll definitely look for that, hope I find something interesting! :) – juliomalegria Jan 30 '12 at 17:00
  • 1
    @julio.alegria: Great :) If you find something, please share it. – Tadeck Jan 30 '12 at 17:18
  • From the looks of it, they found nothing :) – Mysterious Wolf Aug 01 '19 at 08:34
  • 1
    There have been no Python 2 releases since 2.7, and it's going to [end-of-life status on 1 January 2020](https://www.infoq.com/news/2019/09/python-2-end-of-life-approaching/). – Teemu Leisti Nov 07 '19 at 14:41