Why is Python 3 (or later) better than Python 2?

别来无恙 提交于 2019-12-09 16:11:45

问题


I learned Python as my first serious (non BASIC) language about 10 years ago. Since then, I have learned lots of others, but I tend to 'think' in Python. When I look at the list of changes I do not see one I need this feature. I usually say to myself, hmm that would been a good way of doing it, but why change it now?

Things like changing the default floor division could be a real pain to change for big projects. It seems like the major players are dragging their feet. What is the key feature that would make me want to invest in another learning curve?


回答1:


As a key feature, a lot of people seem to be pretty exited about (supposedly) transparent unicode support. They changed it from str (8-bit char array/default string type) and unicode (unicode string), to str (default (unicode compatable) string) and bytes (binary data as 8-bit 'string').

(I think seperation of byte lists from strings is great idea, but I also hate unicode, so if anything, this would be a worse for me personally.)




回答2:


A good discussion of this can be found in the python wiki; Should I use Python 2 or Python 3 for my development activity?




回答3:


Things like changing default floor division could be a real pain to change for big projects.

If you had started making the change 8 years ago when Python 2.2 was introduced with // and from __future__ import division, it wouldn't be a pain now. Personally, I'm glad to finally get rid of old-style division!

My second-favorite feature of Python 3.x is the str/bytes distinction. Besides making Unicode support easier, bytes is far more convenient for database BLOBs than buffer was.




回答4:


On Teaching Programming With Python 3.0, though a bit dated, is one of the best articles I've read on the advantages of Py3k.



来源:https://stackoverflow.com/questions/3384361/why-is-python-3-or-later-better-than-python-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!