python2和python3的区别:
1、通过input()解析用户的输入:(Python3中input得到的为str;Python2的input的到的为int型,
Python2的raw_input得到的为str类型)统一一下:Python3中用input,Python2中用row_input,都输入为str;
2、Python3中/表示真除,%表示取余,//表示地板除(结果取整);Python2中/表示根据
除数被除数小数点位得到结果,//同样表示地板除)统一一下:Python3中/表示真除,
%表示取余,//结果取整;Python2中带上小数点/表示真除,%表示取余,//结果取整
Python 2.7.6
3 / 2 = 1
3 // 2 = 1
3 / 2.0 = 1.5
3 // 2.0 = 1.0
Python 3.4.1
3 / 2 = 1.5
3 // 2 = 1
3 / 2.0 = 1.5
3 // 2.0 = 1.0
3、https://www.cnblogs.com/weikunzz/p/6857971.html 详解
4、python2中range(1,10,2)会生成数字列表,python3中则:list(range(1,10,2))
5、python2x:unicode 默认2个字节表示一个字符 可以在LINUX 编译安装时做调整
python3x:unicode 默认是4个字节表示一个字符
python2中默认的字符串类型默认是ASCII,python3中默认的字符串类型是Unicode。
版本 python2 python3
字节字符串 str bytes
文本字符串 Unicode str
6、
python2中的dict类中的keys、values和items均返回list对象,iterkeys、itervalues和iteritems返回生成器对象。
python3中移除了list、只返回一个生成器的对象,只保留视图(生成器),但方法名为:keys、values和items。
7、模块合并
python2中的StringIO和cStringIO合并为python3中的io
python2中的pickle和cPickle合并为python3中的pickle
python2中的urllib、urllib2和urlparse合并为python3中的urllib
8、重命名模块
python3 python2
Configparser ConfigParser
filter itertools.ifilter
input raw_input
map itertools.imap
range xrange
functools.reduce reduce
socketserver SocketServer
zip itertools.izip