admin 管理员组

文章数量: 894198

python3.0不向后兼容啥意思

Python 3.0是向下兼容的,为什么?

Python 3.0实现了很多非常有用的功能,并打破了向后兼容性。它的目的是,所以伟大的功能可以实现,即使事实上Python 2.x代码可能无法正常工作在Python 3.x下。

所以,基本上,Python 3.0是不是向后兼容的目的。由于这一点,你可以受益于一整套全新的功能。它甚至被称为“Python 3000”或“Python 3K”。

从“Python 3.0的新功能”(可用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在3.0中有新特性,打破了向下兼容性

一些可以被认为是破坏向后兼容性但是同时改进语言的最显着的特征是:

> print现在是一个函数,而不是一个语句,并且使用它作为语句会导致错误,>各种功能&方法现在返回一个迭代器或视图而不是列表,这使得迭代它们的结果更高的内存效率(你不需要将结果的整个列表存储在内存中)>用于排序函数(如sorted()和list.sort())的cmp参数不再受支持,应由键参数替换,> int现在与Python 2.x的long相同,这使得数字处理不那么复杂,> / operator现在是默认情况下真正除法的运算符(您仍然可以使用//进行floor除法),> Python中的文本3.x现在默认为Unicode,> True,False和None都是保留字(所以你不能做True,False = False,True,>改变元类的使用,>异常需要从BaseException派生,必须提出&捕获不同于Python 2.x,>和更多的其他变化,使Python更加可读,一致&显式,

本文标签: python30不向后兼容啥意思