admin管理员组

文章数量:1593934

学习python2还是3

Image Credit: DigitalOcean

图片来源:DigitalOcean

One of the biggest sources of confusion and misinformation for people wanting to learn Python is which version they should learn.

对于想学习Python的人来说,最大的困惑和错误信息来源之一就是他们应该学习哪个版本。

Should I learn Python 2.x or Python 3.x?

我应该学习Python 2.x还是Python 3.x?

Indeed, this is one of the questions we are asked most often at Dataquest, where we teach Python as part of our Data Science curriculum.

的确,这是Dataquest中最常被问到的问题之一,我们在Python中将Python作为我们的数据科学课程的一部分进行教学。

This post gives some context behind the question, explains the pespective, and tells you which version you should learn.

这篇文章提供了问题背后的一些背景,解释了观点,并告诉您应该学习哪个版本。

Let’s start by taking a brief look at the history.

让我们首先简要回顾一下历史。

Python 3.0于2008年发布(不是拼写错误-9年前!) (Python 3.0 was released in 2008 (not a typo – 9 years ago!))

On December 3rd, 2008, Python released version 3.0 . What was special about this was that it was a backwards incompatible release (if you want to read more about why, I recommend this excellent post by Brett Cannon)

在2008年12月3日,Python发布了3.0版。 与此不同的是,它是一个向后不兼容的发行版(如果您想了解更多原因,我推荐Brett Cannon撰写的出色文章 )

As a result, for anyone who was using Python 2.x at that time, migrating their project to 3.x required large changes. This not only included individual projects and applications, but also all the libraries that form part of the Python ecosystem.

结果,对于当时使用Python 2.x的任何人来说,将其项目迁移到3.x都需要进行大量更改。 这不仅包括单个项目和应用程序,还包括构成Python生态系统一部分的所有库。

As a result, the change was seen as extremely controversial, and many projects resisted the pain of moving over, especially in the Scientific Python community. It took two years for the main numeric library NumPy to release its first 3.x release, after which other projects started to release 3.x compatible versions in the years that followed.

结果,这种变化被认为是极富争议的,许多项目都抵制了迁移的痛苦,尤其是在Scientific Python社区中。 主要数字库NumPy用了两年时间才发布了第一个3.x版本,此后其他项目在随后的几年中开始发布3.x兼容版本。

By 2012, a lot of libraries had support for 3.x, but most were still being written in 2.x. Over time, tools were released that made porting code across easier, but there was still a great resistance to move.

到2012年,很多库都支持3.x,但是大多数库仍是用2.x编写的。 随着时间的推移,发布了一些工具,使跨代码的移植变得更加容易,但是仍然存在很大的移动阻力。

A great read on the topic is Jake VanderPlas’ post from 2013: Will Scientists Ever Move to Python 3?

杰克·范德普拉斯(Jake VanderPlas)在2013年发表的一篇文章对此主题做了很好的阅读: 科学家们将转向Python 3吗?

In the few years that followed, several tools were release to help the transition of older codebases from Python 2 to Python 3.

在随后的几年中,发布了一些工具来帮助将旧代码库从Python 2过渡到Python 3。

Originally, Python had scheduled the ‘end of life’ date for Python 2.x for 2015, but in 2014 they announced they would extend this by 5 years to 2020, in part to relieve worries for those users who cannot yet migrate to Python 3.

最初,Python计划将Python 2.x的“生命周期终止”日期定为2015年,但在2014年,他们宣布将这一期限延长5年至2020年,以部分缓解那些尚未迁移到Python 3的用户的后顾之忧。 。

快进到今天 (Fast-forward to today)

Today, there are very few libraries that do not support Python 3. Python 3 Readiness shows that 344 of the 360 top packages for Python support 3.x.

如今,很少有不支持Python 3的库。Python3 Readiness表明,在用于Python的360个顶级软件包中,有344个支持3.x。

In addition, many packages are announcing the end of support for 2.x. Python 3 Statement is a project where many of the main (scientific) libraries are committing to stop supporting 2.x in 2020 or sooner.

此外,许多软件包都宣布终止对2.x的支持。 Python 3 Statement是一个项目,许多主要(科学)库都承诺在2020年或更早时候停止支持2.x。

Recently, the popular web-framework Django announced that their new 2.0 version would not support Python 2.x.

最近,流行的网络框架Django 宣布其新的2.0版本将不支持Python2.x 。

那么为什么这仍然是一个问题? (So why is this still a question?)

There are a lot of older, free resources online to learn Python that are based in Python 2, including most MOOC courses at places like Coursera, Udemy and edX.

在线上有很多旧的免费资源来学习基于Python 2的Python,包括在Coursera,Udemy和edX等地方的大多数MOOC课程。

Added to this, Zed Shaw’s extremely popular ‘Learn Python the Hard Way’ was written in Python 2.x and has not been updated. Until recently, I thought this was just because Zed was too lazy to update his course, but recently he published a controversial article: The Case against Python 3.

除此之外,Zed Shaw极为流行的“学习Python的艰难方法”是用Python 2.x编写的,尚未进行更新。 直到最近,我还认为这仅仅是因为Zed懒于更新自己的课程,但是最近他发表了一篇有争议的文章: Python 3的案例 。

You might also like to read Eevee’s excellent rebuttal: A Rebuttal For Python 3, as well as the thoughts of many software developers in the Hacker News thread for Zed’s article).

您可能还想阅读Eevee的出色反驳: Python 3的反驳 ,以及Zed文章的Hacker News主题中许多软件开发人员的想法)。

In short – the number of people who agree with Zed’s rant are in the extreme minority.

简而言之–同意Zed咆哮的人数很少。

喜欢这篇文章吗? 使用Dataquest学习数据科学! (Enjoying this post? Learn data science with Dataquest!)

  • Learn from the comfort of your browser.
  • Work with real-life data sets.
  • Build a portfolio of projects.
  • 从舒适的浏览器中学习。
  • 处理实际数据集。
  • 建立项目组合。

Start for Free

免费开始

那我应该学习什么呢? (So which should I learn?)

为什么要学习Python 3 (Why you should learn Python 3)

From one perspective, I was lucky enough to enter the world of Python much more recently, in early 2016. I started learning Python as part of the data science curriculum at Dataquest. Dataquest only teaches 3.x, and for quite a time I didn’t know of this whole 2 vs 3 controversy.

从一个角度来看,我很幸运地在2016年初进入了Python的世界。我开始在Dataquest的数据科学课程中学习Python。 Dataquest只讲3.x,而且有一段时间我不知道整个2 vs 3的争论。

I’ve used Python 3.x exclusively and rarely run into compatibility issues.

我只使用过Python 3.x,很少遇到兼容性问题。

Very occasionally (maybe once every 3–4 months), I’ll find I’m trying to run something that requires Python 2 support, and Python’s virtualenv allows me to instantly create a 2.x environment on my machine to run that piece of legacy software.

偶尔(也许每3-4个月一次),我会发现我正在尝试运行一些需要Python 2支持的程序,而Python的virtualenv允许我在计算机上立即创建一个2.x环境来运行该程序。旧版软件。

Python 3.x is the future, and with Python 2.x support dwindling, you should put your time into learning the version that will help you into the future.

Python 3.x是未来,并且随着Python 2.x支持的减少,您应该花时间学习有助于将来的版本。

为什么要学习Python 2 (Why you should learn Python 2)

You shouldn’t. Very soon there will be no future security or bug fixes for Python 2.x, and your time is better spent learning 3.x.

你不应该 很快将不再有Python 2.x的未来安全性或错误修复程序,您的时间最好花在学习3.x上。

In the unlikely event that you end up working with a legacy Python 2 code base, tools like python-future will make it easy for you to use having only learned Python 3.

万一您最终无法使用旧版Python 2代码库,则像python-future这样的工具将使您仅学习Python 3即可轻松使用。



I hope this has helped you understand this controversial topic and make your decision to learn Python 3.

我希望这可以帮助您理解这个有争议的主题,并决定学习Python 3。

Dataquest is the best online platform for learning to be a Data Scientist using Python (3.x, of course!).

Dataquest是学习使用Python成为数据科学家的最佳在线平台(当然是3.x!)。

翻译自: https://www.pybloggers/2017/07/should-i-learn-python-2-or-3/

学习python2还是3

本文标签: Python