开发者

Learn Python 3.0 or 2.x? [duplicate]

开发者 https://www.devze.com 2023-03-23 07:09 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Tutorial for Python - Should I use 2.x or 3.0?
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Tutorial for Python - Should I use 2.x or 3.0?

I have decided to learn python. I have used in the past Java/c++/PHP/Action Script. Should I learn 3.0 or 2.x? Are the majority of libraries still in 2.x? Which book do you recommend? I posted this as I开发者_开发百科 would like an up-to-date answer to this question.

Thanks


Almost all production software is still written in python 2.x at the moment. You should learn python 2.x, as it is installed much more widely and has many more third party libraries available. Eventually the world will move to 3.x, but the differences are not massive so your effort learning 2.x will not have been wasted.

Have a look at this FAQ: http://wiki.python.org/moin/Python2orPython3

Unscientific snapshot: of available packages on pypi, there are 493 in python 3, of 11053 packages in total at time of writing (July 2011)


Start with learning Python! The diffrences are not really important for beginners. After you did some basic programming tasks and you feel as a more advanced user you can look at the diffrences and see what better fits for you.

Since there are so many compatiblity issues s tart out with python 2 since you will have so many external libraries you can use.

And if you have an idea on a own project and think you can live without all the external libraries go with python and help to make the switch so that at one day we won't have this issue anymore.

But for now do 2.7.

Hope this helps.


I recommend starting with Version 2.7, but put the following lines at the top of every new source file.

#!/usr/bin/python2
# -*- coding: utf-8 -*-

from __future__ import absolute_import
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division

That will make it behave more like 3.x so you also get used to that functionality and syntax (print function, especially).


Learn Python 3, then learn the differences so you can code in 2 and work with 2. They are pretty similar to each other.

The logic of "Well, most packages use 2, so learn 2." is a similar argument to "Don't bother learning anything about IPv6, everybody still uses IPv4.". The future is 3, that past is 2. 3 is clearly better than 2, and 2 is at the end of its development life and will see no major new development. When the GIL is fixed, it will be fixed in 3, not 2.

So, learn 3, then learn the differences. They aren't very different, and the major rev was largely so backward compatibility could be broken for some important things that while seemingly minor, really needed to be fixed.

0

精彩评论

暂无评论...
验证码 换一张
取 消