为什么Python 3不向后兼容? [英] Why is Python 3 not backwards compatible?

查看:456
本文介绍了为什么Python 3不向后兼容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解到Python 3不向后兼容.

I have learned that Python 3 is not backwards compatible.

使用旧版本的Python会不会影响很多应用程序?

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

Python 3的开发人员怎么不认为使其向后兼容绝对必要?

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

推荐答案

Python 3.0向后兼容,为什么?

Python 3.0实现了许多非常有用的功能,并破坏了向后兼容性.它是故意这样做的,因此即使Python 2.x代码在Python 3.x下可能无法正常工作,也可以实现出色的功能.

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.

因此,基本上, Python 3.0并非有意向后兼容. 为此,您可以从全新功能中受益.它甚至被称为" Python 3000 "或" Python 3K ".

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".

来自" Python 3.0的新增功能"(可用

Python 3.0,与2.6相比. Python 3.0(也称为"Python 3000"或"Py3K")是第一个有意向后不兼容的Python版本.与典型发行版相比,存在更多的更改,而这些更改对于所有Python用户而言都非常重要.不过,在消化了这些变化之后,您会发现Python并没有真正改变太多–总的来说,我们主要是在修复众所周知的烦恼和疣,并消除很多旧的残渣 strong>.

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 3.0中的新功能,打破了向后兼容性

一些最显着的功能可能被认为是破坏了向后兼容性,但同时又改进了语言,这些功能是:

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现在是一个函数,而不是一个语句,将其用作语句将导致错误,
  • 各种功能和功能方法现在返回一个迭代器或视图而不是列表,这使遍历其结果的内存效率更高(您无需将结果的整个列表存储在内存中),
  • 不再支持用于sorted()list.sort()之类的排序功能的
  • cmp自变量,应替换为key自变量
  • int现在与Python 2.x的long相同,这使得数字处理不再那么复杂
  • /运算符现在默认为真正除法运算符(您仍然可以使用//进行地板除法)
  • Python 3.x中的文本现在默认为Unicode,
  • TrueFalseNone现在是保留字(因此您无法执行True, False = False, True
  • 更改了元类的用法,
  • 必须从BaseException派生
  • 例外,并且必须引发&;捕获的方式与Python 2.x中的捕获方式不同,
  • 以及更多其他更改,使Python更具可读性,更一致&明确的
  • 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,

这篇关于为什么Python 3不向后兼容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆