python2与python3的区别,python2python3,为什么要有pytho


为什么要有python3:

In November 2014, it was announced that Python 2.7 would be supported until 2020, and reaffirmed that there would be no 2.8 release as users were expected to move to Python 3.4+ as soon as possible

区别1:

python2:源码不规范,源码混乱,重复代码较多(在python刚出世时,各界大牛如Java,PHP,C等,为python添加了功能,导致源码混乱)

python3:牛逼的龟叔看到python2,操了,一气之下又写了python3:重整源码,源码规范,优美,清晰,简单

区别2:

Python2:默认编码方式为ASCii 码

python3: 默认编码方式为UTF-8

区别3:

python2:中的print ‘ 内容‘ 或者 print(‘内容’)

python3中print只能是print(‘内容’)

区别4:

python2中:raw_input()得到的为字符串型,input() 为内置函数eval()

python3中:input() 得到的数据类型为为字符串型

区别5:

python2中有两种字符串类型str和unicode 这里str = bytes

python3 中也有两种字符串类型str和bytes 这里 str = unicode

区别6:

python2中:range是一个数字列表,xrange是一个可迭代对象,迭代器

python3中:range是一个迭代器

区别7:

python2中:无nonlocal

python3中:有nonlacal,用来修改函数中上一层的变量。

区别8:

python2中:创建一个类,该类或者其继承的父类中,要是没有继承object类,那么该类就是一个经典类,继承顺序是深度优先

python3中:创建一个类,该类默认继承了object类,所以python3中的类都是新式类,继承顺序为广度优先

python2与python3的区别

评论关闭