1、整数:python2中区分整型(int)和长整型(long),python3不区分;
2、python2中没有f 标志位格式化,python3才有;
3、python3里面,True和False都是关键字,python2里面不是;
4、python2中的整数相除属于地板除,要想真除就得变成浮点数
python3中的整数相除就是真除
5、python2的编码是ascii码,python3的默认编码是utf8
若是要python2中要输入汉文的话,要在前边说明"encoding = utf-8"
6、包结构的目录里有一个——int_.py模块。py2,_init_.py是必须的;py3,_init_.py是可选的
比如:。这里,py2只会识别pack02是一个包,而py3都会识别成包
7、模块运行的时候。python2,只会在模块同级目录下生成.pyc文件;python3会生成__pycache__目录文件。
8、输出和输入
输出:
python2的print不一定要求函数形式使用,python2可以这样输出print"hello"
python3的print强制是函数,例如,print("hello")
输入:
python3中input得到的数据类型都是str
python2中的input默认是int,str要使用引号包裹,raw_input得到的数据类型都是str
Python 2.7.5 (default, Oct 14 2020, 14:45:30)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print "hello"
hello
>>> print ("hello")
hello
>>>
KeyboardInterrupt
[root@fttsaxf ~]# python3
Python 3.6.8 (default, Nov 16 2020, 16:55:22)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> print("hello")
hello
9、输入函数input的区别
python2里边原来的input被淘汰了(但是还能使用),变成了raw_input就是python3中的input
python2:
- input() #如果输入是一个数学计算式,会自动执行计算得出结果,并且会自动识别出输入的类型(str,int,float)
- raw_input() #完全默认为str类型
python3:
input(),默认就是str类型
10、range的区别
列表一定是可迭代对象,可迭代对象不一定是列表
range和xrange
python2,range(0,4) -->结果:[0,1,2,3];xrange(0,4) -->结果是一个可迭代对象,是一个惰性求值,即使用的时候再生成值
python3,没有xrange,python3的range函数就是python2的xrange
11、异常捕获差异:
python2,except Exception,e:
python3, except Exception as e: