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?

5
  • 5
    Of course it won't affect them, they're run under Python 2.
    – Wooble
    Jan 30, 2012 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, 2015 at 15:34
  • @blong: maybe, but you'd probably have to rewrite the question as well.
    – Wooble
    Jul 23, 2015 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, 2015 at 16:26
  • Nope, it wouldnt be.
    – neelmeg
    Feb 22, 2016 at 2:35

1 Answer 1

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,
8
  • 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. Jan 30, 2012 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": "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, 2012 at 16:42
  • 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, 2012 at 16:56
  • 1
    I'll definitely look for that, hope I find something interesting! :) Jan 30, 2012 at 17:00
  • 1
    @julio.alegria: Great :) If you find something, please share it.
    – Tadeck
    Jan 30, 2012 at 17:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.