python2x与python3x区别汇总

Python2和Python3的区别:
1.Python2源码重复,不规范;Python3源码规范,清晰,简单。

2.python2默认编码UTF-8,代码首行加入# -*- encoding:utf-8 -*-
 Python3默认编码utf-8。

3.python2中的整数的除运算得到的结果会舍弃小数位,变成整除,而python3中会保留小数位

  例:

1         3/2 = 1.5 #python3里的结果

2       3/2 = 1 #python2里的结果 

  如果需要在python2中避免这种情况,可以使用下述方法:

1 3.0 / 2 = 1.5
2 3 / 2.0 = 1.5
3 3.0 / 2.0 =1.5

 

  

 

 

posted @ 2018-08-03 16:52  AbnerLing  阅读(229)  评论(0)    收藏  举报