py2和py3的区别总结

时间:2022-02-16 01:41:16

1.编码

python2默认编码方式ASCII码(不能识别中文,要在文件头部加上  #-*- encoding:utf-8 -*-  指定编码方式)

python3默认编码方式unicode(可识别中文)

 2.print

python2中加不加括号都可以打印

python3中必须加括号

3.input

python2 raw_input()
python3 input()

 4.range()

python2 range()/xrange()
python3 range()

5.类

python3中都是新式类
python2.7中经典类和新式类混合

新式类中使用广度优先,经典类中使用深度优先

python3可以使用super
python2不能使用super

 

....持续更新中