为什么 Python 3 不向后兼容?
我了解到 Python 3 不向后兼容。
它不会影响很多使用旧版本Python的应用程序吗?
Python 3 的开发者为什么不认为绝对有必要使其向后兼容呢?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Python 3.0 向后兼容吗?为什么?
Python 3.0 实现了很多非常有用的功能,但破坏了向后兼容性。它是有意这样做的,因此即使 Python 2.x 代码在 Python 3.x 下可能无法正常工作,也可以实现出色的功能。
因此,基本上,Python 3.0 并不是故意向后兼容的。 因此,您可以从一组全新的功能中受益。它甚至被称为“Python 3000”或“Python 3K”。
来自“Python 3.0 中的新增功能”(可用 在这里):
Python 3.0 中的新功能打破了向后兼容性
一些最显着的功能可能被认为打破了向后兼容性,但同时改进了语言,它们是:
print
现在是一个函数,而不是一个语句,并将其用作语句会导致错误,cmp
参数像sorted()
和list.sort()
不再支持,应该用key
参数替换,int 现在与 Python 2.x 相同
long
,这使得数字处理变得不那么复杂,/
运算符现在默认是真正除法的运算符(您仍然可以使用//
来表示底数)除法),True
、False
和None
现在是保留字(因此您不需要能够做到True, False = False, True
,BaseException
派生,必须以与 Python 2.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.
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 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,cmp
argument for sorting functions likesorted()
andlist.sort()
is no longer supported, and should be replaced bykey
argument,int
is now the same as Python 2.x'slong
, which makes number processing less complex,/
operator is now an operator for true division by default (you can still use//
for floor division),True
,False
andNone
are now reserved words (so you are not able to doTrue, False = False, True
,BaseException
, must be raised & caught differently than in Python 2.x,